All Projects → yegor256 → futex

yegor256 / futex

Licence: MIT license
File-based Ruby Mutex

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to futex

mutexsafe
MutexSafe will help you use mutex more effectively. Different mutex for different components are presented. In addition, you can add your own lockers and use within the library.
Stars: ✭ 15 (+7.14%)
Mutual labels:  lock, locking, mutex
async
Synchronization and asynchronous computation package for Go
Stars: ✭ 104 (+642.86%)
Mutual labels:  concurrency, lock, mutex
AtomicKit
Concurrency made simple in Swift.
Stars: ✭ 88 (+528.57%)
Mutual labels:  concurrency, lock, mutex
django-concurrency-talk
🎭 Database Integrity in Django: Safely Handling Critical Data in Distributed Systems
Stars: ✭ 49 (+250%)
Mutual labels:  concurrency, lock
distlock
The universal component of distributed locks in golang , support redis and postgresql
Stars: ✭ 60 (+328.57%)
Mutual labels:  lock, mutex
Java Concurrency Examples
Java Concurrency/Multithreading Tutorial with Examples for Dummies
Stars: ✭ 173 (+1135.71%)
Mutual labels:  concurrency, lock
nativescript-http
The best way to do HTTP requests in NativeScript, a drop-in replacement for the core HTTP with important improvements and additions like proper connection pooling, form data support and certificate pinning
Stars: ✭ 32 (+128.57%)
Mutual labels:  concurrency, threads
noroutine
Goroutine analogue for Node.js, spreads I/O-bound routine calls to utilize thread pool (worker_threads) using balancer with event loop utilization. 🌱
Stars: ✭ 86 (+514.29%)
Mutual labels:  concurrency, threads
go-lock
go-lock is a lock library implementing read-write mutex and read-write trylock without starvation
Stars: ✭ 78 (+457.14%)
Mutual labels:  lock, mutex
thread-pool
A modern thread pool implementation based on C++20
Stars: ✭ 104 (+642.86%)
Mutual labels:  concurrency, threads
optimistic lock coupling rs
🍋: A General Lock following paper "Optimistic Lock Coupling: A Scalable and Efficient General-Purpose Synchronization Method"
Stars: ✭ 21 (+50%)
Mutual labels:  concurrency, lock
haxe-concurrent
A haxelib for basic platform-agnostic concurrency support
Stars: ✭ 69 (+392.86%)
Mutual labels:  concurrency, lock
Mt
tlock, RWMUTEX, Collab, USM, RSem and other C++ templates for Windows to provide read/write mutex locks, various multithreading tools, collaboration, differential updates and more
Stars: ✭ 18 (+28.57%)
Mutual labels:  concurrency, lock
Crossbeam
Tools for concurrent programming in Rust
Stars: ✭ 4,180 (+29757.14%)
Mutual labels:  concurrency, threads
Concurrent
Functional Concurrency Primitives
Stars: ✭ 206 (+1371.43%)
Mutual labels:  concurrency, lock
concurrency-kit
🚄 Concurrency abstractions framework for Apple Platforms [Task, Atomic, Lock, Operation, etc.].
Stars: ✭ 17 (+21.43%)
Mutual labels:  concurrency, mutex
aiorwlock
Read/Write Lock - synchronization primitive for asyncio
Stars: ✭ 90 (+542.86%)
Mutual labels:  concurrency, lock
TAOMP
《多处理器编程的艺术》一书中的示例代码实现,带有注释与单元测试
Stars: ✭ 39 (+178.57%)
Mutual labels:  concurrency, lock
pglock
PostgreSQL Lock Client for Go
Stars: ✭ 50 (+257.14%)
Mutual labels:  lock, locking
wasm-bindgen-rayon
An adapter for enabling Rayon-based concurrency on the Web with WebAssembly.
Stars: ✭ 257 (+1735.71%)
Mutual labels:  concurrency, threads

EO principles respected here DevOps By Rultor.com We recommend RubyMine

Build Status Build status Gem Version Maintainability Yard Docs

Hits-of-Code License

Sometimes you need to synchronize your block of code, but Mutex is too coarse-grained, because it always locks, no matter what objects your code accesses. The Futex (from "file mutex") is more fine-grained and uses a file as an entrance lock to your code.

First, install it:

$ gem install futex

Then, use it like this:

require 'futex'
Futex.new('/tmp/my-file.txt').open do |f|
  IO.write(f, 'Hello, world!')
end

The file /tmp/my-file.txt.lock will be created and used as an entrance lock. It will won't be deleted afterwards.

If you are not planning to write to the file, it is recommended to get a non-exclusive/shared access to it, by providing false to the method open():

require 'futex'
Futex.new('/tmp/my-file.txt').open(false) do |f|
  IO.read(f)
end

For better traceability you can provide a few arguments to the constructor of the Futex class, including:

  • log: an object that implements debug() method, which will receive supplementary messages from the locking mechanism;

  • logging: set it to true if you want to see logs;

  • timeout: the number of seconds to wait for the lock availability (Futex::CantLock exception is raised when the wait is expired);

  • sleep: the number of seconds to wait between attempts to acquire the lock file (the smaller the number, the more responsive is the software, but the higher the load for the file system and the CPU);

  • lock: the absolute path of the lock file;

That's it.

How to contribute

Read these guidelines. Make sure you build is green before you contribute your pull request. You will need to have Ruby 2.3+ and Bundler installed. Then:

$ bundle update
$ bundle exec rake

If it's clean and you don't see any error messages, submit your pull request.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].