• Places
    • Home
    • Graphs
    • Prefixes
  • Admin
    • Users
    • Settings
    • Plugins
    • Statistics
  • CPACK
    • Home
    • List packs
    • Submit pack
  • Repository
    • Load local file
    • Load from HTTP
    • Load from library
    • Remove triples
    • Clear repository
  • Query
    • YASGUI SPARQL Editor
    • Simple Form
    • SWISH Prolog shell
  • Help
    • Documentation
    • Tutorial
    • Roadmap
    • HTTP Services
  • Login

A.51 library(rwlocks): Read/write locks
All Application Manual Name SummaryHelp

  • Documentation
    • Reference manual
      • The SWI-Prolog library
        • library(rwlocks): Read/write locks
          • with_rwlock/3
          • with_rwlock/4
    • Packages
Availability::- use_module(library(rwlocks)).(can be autoloaded)
Sourcewith_rwlock(+LockId, :Goal, +ModeSpec)
with_rwlock(+LockId, :Goal, +ModeSpec, +Options)
Run Goal, synchronized with LockId in ModeSpec. ModeSpec is one of read, write, read(Priority) or write(Priority). The default read priority is 100 and the default write priority is 200. These values prioritize writers over readers. Goal may start if

  • If there is no goal waiting with higher priority and

    • It is a read goal and no write goal is running or
    • It is a write goal and no other goal is running.

If Goal may not start immediately the thread waits using thread_wait/2. The Options timeout and deadline are passed to thread_wait/2. If the time limit is exceeded an exception is raised.

Read/write locks are widely critized for their poor behaviour on several workloads. They perform well in scenarios where read operations take long, and write operations are relatively fast and occur only occasionally. Transactions, as implemented by transaction/1,2 are often a better alternative.

This predicate uses a normal mutex and a flag with the same name. See with_mutex/2 and flag/3. Neither the mutex nor the flag should be used directly.

throws
time_limit_exceeded(rwlock) if a timeout or deadline is specified and this is exceeded.
bug
The current implementation is written in Prolog and comes with significant overhead. It is intended to synchronize slow operations.
ClioPatria (version V3.1.1-51-ga0b30a5)