sleeplocks alternatives and similar packages
Based on the "Algorithms and Data structures" category.
Alternatively, view sleeplocks alternatives based on common mentions on social networks and blogs.
-
matrex
A blazing fast matrix library for Elixir/Erlang with C implementation using CBLAS. -
simple_bayes
A Naive Bayes machine learning implementation in Elixir. -
exconstructor
An Elixir library for generating struct constructors that handle external data with ease. -
erlang-algorithms
Implementations of popular data structures and algorithms -
remodel
:necktie: An Elixir presenter package used to transform map structures. "ActiveModel::Serializer for Elixir" -
aja
Extension of the Elixir standard library focused on data stuctures, data manipulation and performance -
MapDiff
Calculates the difference between two (nested) maps, and returns a map representing the patch of changes. -
parallel_stream
A parallelized stream implementation for Elixir -
merkle_tree
:evergreen_tree: Merkle Tree implementation in pure Elixir -
bloomex
:hibiscus: A pure Elixir implementation of Scalable Bloom Filters -
the_fuzz
String metrics and phonetic algorithms for Elixir (e.g. Dice/Sorensen, Hamming, Jaccard, Jaro, Jaro-Winkler, Levenshtein, Metaphone, N-Gram, NYSIIS, Overlap, Ratcliff/Obershelp, Refined NYSIIS, Refined Soundex, Soundex, Weighted Levenshtein) -
DeepMerge
Deep (recursive) merge for maps, keywords and others in Elixir -
exmatrix
Elixir library implementing a parallel matrix multiplication algorithm and other utilities for working with matrices. Used for benchmarking computationally intensive concurrent code. -
ecto_materialized_path
Tree structure & hierarchy for ecto models -
dataframe
Package providing functionality similar to Python's Pandas or R's data.frame() -
Conrex
An Elixir implementation of the CONREC algorithm for topographic or isochrone maps. -
murmur
:speech_balloon: An implementation of the non-cryptographic hash Murmur3 -
bitmap
Bitmap implementation in Elixir using binaries and integers. Fast space efficient data structure for lookups -
Closure Table
Closure Table for Elixir - a simple solution for storing and manipulating complex hierarchies. -
combination
A simple combinatorics library providing combination and permutation.
InfluxDB - Power Real-Time Data Analytics at Scale
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of sleeplocks or a related project?
Popular Comparisons
README
sleeplocks
This library is designed to provide simple locking mechanisms in Erlang/Elixir, similar to how spinlocks work in other languages - except using messages to communicate locking.
This is useful for libraries which require lock synchronization, without having to roll your own (however simple). Locks can be held by arbitrary numbers of process, making it possible to implement various throttling mechanisms.
Best of all, this library is tiny! It builds upon basic OTP principles to implement lock behaviour via simple processes and message passing.
Installation
Rebar
Follow the instructons found here to configure your Rebar setup to use Hex as a dependency source, then you can grab it directly:
{deps,[
% pulls the latest version
sleeplocks,
% to pull the latest version from github
{sleeplocks, {git, "git://github.com/whitfin/sleeplocks.git"}}
]}.
Mix
To install it for your project, you can pull it directly from Hex. Rather than use the version shown below, you can use the latest version from Hex (shown at the top of this README).
def deps do
[{:sleeplocks, "~> 1.0"}]
end
Usage
Snippets below contain sample usage in both Erlang and Elixir, and cover most of the small
API space offered by sleeplocks
. For a more complete example, scroll down!
Erlang
% create a new single lock (with a name)
1> sleeplocks:new(1, [{name, {local, my_lock}}]).
{ok,<0.179.0>}
% take ownership of the lock
2> sleeplocks:acquire(my_lock).
ok
% release the current hold on a lock
3> sleeplocks:release(my_lock).
ok
% attempt to acquire a lock (which will succeed)
4> sleeplocks:attempt(my_lock).
ok
% now that it's taken, other attempts will fail
5> sleeplocks:attempt(my_lock).
{error,unavailable}
% release the lock again
6> sleeplocks:release(my_lock).
ok
% handle acquisition and locking automatically
7> sleeplocks:execute(my_lock, fun() ->
7> 3
7> end).
3
Elixir
# create a new single lock (with a name)
iex(1)> :sleeplocks.new(1, [ name: :my_lock ])
{:ok, #PID<0.179.0>}
# take ownership of the lock
iex(2)> :sleeplocks.acquire(:my_lock)
:ok
# release the current hold on a lock
iex(3)> :sleeplocks.release(:my_lock)
:ok
# attempt to acquire a lock (which will succeed)
iex(4)> :sleeplocks.attempt(:my_lock)
:ok
# now that it's taken, other attempts will fail
iex(5)> :sleeplocks.attempt(:my_lock)
{:error, :unavailable}
# release the lock again
iex(6)> :sleeplocks.release(:my_lock)
:ok
% handle acquisition and locking automatically
iex(7)> :sleeplocks.execute(:my_lock, fn ->
iex(7)> 3
iex(7)> end)
3
Examples
This example is in Elixir, but it should be fairly understandable for those coming from both languages. It simply spawns 6 processes which each attempt to hold a lock for 10 seconds. As the lock is created with only 2 slots, this runs for 30 seconds and 2 of our spawned tasks can hold the lock at any given time.
# First create a new lock, with 2 slots only
{:ok, ref} = :sleeplocks.new(2)
# Then spawn 6 tasks, which each just sleep for 10 seconds
# after acquiring the lock. This means that 2 processes will
# acquire a lock and then release after 10 seconds. This
# will repeat 3 times (6 / 2) until 30 seconds are up.
for idx <- 1..6 do
Task.start(fn ->
:sleeplocks.execute(ref, fn ->
IO.puts("Locked #{idx}")
Process.sleep(10_000)
IO.puts("Releasing #{idx}")
end)
end)
end