/usr/local/lib/swipl/library/rwlocks.pl
All Application Manual Name SummaryHelp

  • swipl
    • library
      • error.pl
      • debug.pl
      • apply.pl -- Apply predicates on a list
      • lists.pl
      • broadcast.pl
      • shlib.pl
      • option.pl -- Option list processing
      • thread_pool.pl
      • gensym.pl
      • settings.pl -- Setting management
      • arithmetic.pl
      • main.pl -- Provide entry point for scripts
      • readutil.pl
      • operators.pl
      • pairs.pl -- Operations on key-value lists
      • prolog_source.pl
      • record.pl
      • quasi_quotations.pl
      • pure_input.pl -- Pure Input from files and streams
      • solution_sequences.pl -- Modify solution sequences
      • ordsets.pl
      • random.pl
      • base64.pl -- Base64 encoding and decoding
      • aggregate.pl
      • yall.pl
      • sandbox.pl -- Sandboxed Prolog code
      • apply_macros.pl -- Goal expansion rules to avoid meta-calling
      • assoc.pl
      • prolog_format.pl
      • predicate_options.pl
      • csv.pl -- Process CSV (Comma-Separated Values) data
      • pprint.pl
      • atom.pl
      • modules.pl
      • occurs.pl -- Finding and counting sub-terms
      • prolog_xref.pl
      • prolog_colour.pl
      • lazy_lists.pl -- Lazy list handling
      • ugraphs.pl
      • url.pl
      • www_browser.pl -- Open a URL in the users browser
      • prolog_pack.pl
      • git.pl -- Run GIT commands
      • utf8.pl -- UTF-8 encoding/decoding on lists of character codes.
      • dialect.pl
      • system.pl -- System utilities
      • terms.pl
      • date.pl
      • persistency.pl
      • iostream.pl -- Utilities to deal with streams
      • prolog_stack.pl -- Examine the Prolog stack
      • edinburgh.pl -- Some traditional Edinburgh predicates
      • prolog_clause.pl
      • prolog_breakpoints.pl -- Manage Prolog break-points
      • wfs.pl
      • prolog_code.pl
      • sort.pl
      • dicts.pl
      • dif.pl
      • varnumbers.pl
      • pio.pl -- Pure I/O
      • base32.pl -- Base32 encoding and decoding
      • charsio.pl -- I/O on Lists of Character Codes
      • codesio.pl
      • coinduction.pl -- Co-Logic Programming
      • heaps.pl
      • rbtrees.pl -- Red black trees
      • statistics.pl
      • when.pl -- Conditional coroutining
      • backcomp.pl
      • tty.pl
      • ctypes.pl -- Character code classification
      • thread.pl
      • streams.pl
      • increval.pl
      • tables.pl
      • ansi_term.pl
      • macros.pl
      • qsave.pl
      • zip.pl -- Access resource ZIP archives
      • prolog_autoload.pl
      • check.pl
      • prolog_versions.pl
      • portray_text.pl
      • nb_set.pl
      • hashtable.pl -- Hash tables
      • edit.pl
      • listing.pl -- List programs and pretty print clauses
      • prolog_wrap.pl
      • make.pl
      • optparse.pl
      • prolog_trace.pl
      • fastrw.pl
      • threadutil.pl -- Interactive thread utilities
      • prolog_history.pl
      • prolog_config.pl
      • readln.pl
      • quintus.pl
      • explain.pl
      • prolog_codewalk.pl -- Prolog code walker
      • files.pl
      • prolog_metainference.pl
      • writef.pl
      • prolog_jiti.pl
      • help.pl
      • shell.pl -- Elementary shell commands
      • rwlocks.pl -- Read/write locks
        • with_rwlock/3
        • with_rwlock/4
      • prolog_coverage.pl -- Coverage analysis tool
      • prolog_debug.pl -- User level debugging tools
      • strings.pl
      • prolog_profile.pl
      • exceptions.pl
 with_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.