Generic Locks

DataAxesFormats.GenericLocks Module

Generic (enhanced) read-write locks, which arguably should belong in a more general-purpose package.

These add functionality on top of ConcurrentUtils ; specifically, they allow querying the status of the lock.

Warning

This code relies on tasks staying on the same thread, so always specify @threads :static when using them, otherwise bad things will happen.

Note

We do not re-export the types and functions defined here from the top-level DataAxesFormats namespace. That is, even if using DataAxesFormats , you will not have these generic names polluting your namespace. If you do want to reuse them in your code, explicitly write using DataAxesFormats.GenericLocks .

Write Lock

DataAxesFormats.GenericLocks.write_lock Function
write_lock(query_read_write_lock::QueryReadWriteLock, what::Any...)::Nothing

Obtain a write lock. Each call must be matched by write_unlock . It is possible to nest write_lock / write_unlock call pairs.

When a thread has a write lock, no other thread can have any lock.

The log messages includes what is being locked.

DataAxesFormats.GenericLocks.write_unlock Function
write_unlock(query_read_write_lock::QueryReadWriteLock, what::Any)::Nothing

Release a write lock. Each call must matched a call to write_lock . It is possible to nest write_lock / write_unlock call pairs.

The log messages includes what is being unlocked.

Read Locks

DataAxesFormats.GenericLocks.read_lock Function
read_lock(query_read_write_lock::QueryReadWriteLock, what::Any...)::Bool

Obtain a read lock. Each call must be matched by read_unlock . It is possible to nest read_lock / read_unlock call pairs, even inside write_lock / write_unlock pair(s); however, you can't nest write_lock / write_unlock inside a read_lock / read_unlock pair.

When a thread has a read lock, no other thread can have a write lock, but other threads may also have a read lock.

The log messages includes what is being locked.

Returns whether this is the top-level read lock (as opposed to a nested one).

DataAxesFormats.GenericLocks.read_unlock Function
read_unlock(query_read_write_lock::QueryReadWriteLock, what::Any...)::Nothing

Release a read lock. Each call must matched a call to read_lock . It is possible to nest read_lock / read_unlock call pairs.

The log messages includes what is being unlocked.

DataAxesFormats.GenericLocks.has_read_lock Function
has_read_lock(query_read_write_lock::QueryReadWriteLock; read_only::Bool = false)::Bool

Return whether the current thread has a read lock or the write lock. If read_only is set, then this will only return whether the current thread as a read lock.

Index