1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-29 22:40:34 +02:00

Update documentation on mutexes

* doc/ref/api-scheduling.texi (Mutexes and Condition Variables):
  Update.
This commit is contained in:
Andy Wingo 2016-11-06 18:11:25 +01:00
parent 03ffd726df
commit 16fe02aa15

View file

@ -466,36 +466,28 @@ function is equivalent to calling @code{make-mutex} with the
@code{recursive} kind. @code{recursive} kind.
@end deffn @end deffn
@deffn {Scheme Procedure} lock-mutex mutex [timeout [owner]] @deffn {Scheme Procedure} lock-mutex mutex [timeout]
@deffnx {C Function} scm_lock_mutex (mutex) @deffnx {C Function} scm_lock_mutex (mutex)
@deffnx {C Function} scm_lock_mutex_timed (mutex, timeout, owner) @deffnx {C Function} scm_timed_lock_mutex (mutex, timeout)
Lock @var{mutex}. If the mutex is already locked, then block and Lock @var{mutex} and return @code{#t}. If the mutex is already locked,
return only when @var{mutex} has been acquired. then block and return only when @var{mutex} has been acquired.
When @var{timeout} is given, it specifies a point in time where the When @var{timeout} is given, it specifies a point in time where the
waiting should be aborted. It can be either an integer as returned waiting should be aborted. It can be either an integer as returned
by @code{current-time} or a pair as returned by @code{gettimeofday}. by @code{current-time} or a pair as returned by @code{gettimeofday}.
When the waiting is aborted, @code{#f} is returned. When the waiting is aborted, @code{#f} is returned.
When @var{owner} is given, it specifies an owner for @var{mutex} other For standard mutexes (@code{make-mutex}), an error is signalled if the
than the calling thread. @var{owner} may also be @code{#f}, thread has itself already locked @var{mutex}.
indicating that the mutex should be locked but left unowned.
For standard mutexes (@code{make-mutex}), and error is signalled if
the thread has itself already locked @var{mutex}.
For a recursive mutex (@code{make-recursive-mutex}), if the thread has For a recursive mutex (@code{make-recursive-mutex}), if the thread has
itself already locked @var{mutex}, then a further @code{lock-mutex} itself already locked @var{mutex}, then a further @code{lock-mutex}
call increments the lock count. An additional @code{unlock-mutex} call increments the lock count. An additional @code{unlock-mutex}
will be required to finally release. will be required to finally release.
If @var{mutex} was locked by a thread that exited before unlocking it, When an asynchronous interrupt (@pxref{Asyncs}) is scheduled for a
the next attempt to lock @var{mutex} will succeed, but thread blocked in @code{lock-mutex}, Guile will interrupt the wait, run
@code{abandoned-mutex-error} will be signalled. the interrupts, and then resume the wait.
When an async (@pxref{Asyncs}) is activated for a thread blocked in
@code{lock-mutex}, the wait is interrupted and the async is executed.
When the async returns, the wait resumes.
@end deffn @end deffn
@deftypefn {C Function} void scm_dynwind_lock_mutex (SCM mutex) @deftypefn {C Function} void scm_dynwind_lock_mutex (SCM mutex)
@ -505,31 +497,18 @@ context is entered and to be unlocked when it is exited.
@deffn {Scheme Procedure} try-mutex mx @deffn {Scheme Procedure} try-mutex mx
@deffnx {C Function} scm_try_mutex (mx) @deffnx {C Function} scm_try_mutex (mx)
Try to lock @var{mutex} as per @code{lock-mutex}. If @var{mutex} can Try to lock @var{mutex} and return @code{#t} if successful, or @code{#f}
be acquired immediately then this is done and the return is @code{#t}. otherwise. This is like calling @code{lock-mutex} with an expired
If @var{mutex} is locked by some other thread then nothing is done and timeout.
the return is @code{#f}.
@end deffn @end deffn
@deffn {Scheme Procedure} unlock-mutex mutex [condvar [timeout]] @deffn {Scheme Procedure} unlock-mutex mutex
@deffnx {C Function} scm_unlock_mutex (mutex) @deffnx {C Function} scm_unlock_mutex (mutex)
@deffnx {C Function} scm_unlock_mutex_timed (mutex, condvar, timeout) Unlock @var{mutex}. An error is signalled if @var{mutex} is not locked.
Unlock @var{mutex}. An error is signalled if @var{mutex} is not locked
and was not created with the @code{unchecked-unlock} flag set, or if
@var{mutex} is locked by a thread other than the calling thread and was
not created with the @code{allow-external-unlock} flag set.
If @var{condvar} is given, it specifies a condition variable upon ``Standard'' and ``recursive'' mutexes can only be unlocked by the
which the calling thread will wait to be signalled before returning. thread that locked them; Guile detects this situation and signals an
(This behavior is very similar to that of error. ``Unowned'' mutexes can be unlocked by any thread.
@code{wait-condition-variable}, except that the mutex is left in an
unlocked state when the function returns.)
When @var{timeout} is also given and not false, it specifies a point in
time where the waiting should be aborted. It can be either an integer
as returned by @code{current-time} or a pair as returned by
@code{gettimeofday}. When the waiting is aborted, @code{#f} is
returned. Otherwise the function returns @code{#t}.
@end deffn @end deffn
@deffn {Scheme Procedure} mutex-owner mutex @deffn {Scheme Procedure} mutex-owner mutex
@ -593,13 +572,8 @@ Wake up one thread that is waiting for @var{condvar}.
Wake up all threads that are waiting for @var{condvar}. Wake up all threads that are waiting for @var{condvar}.
@end deffn @end deffn
@sp 1 Guile also includes some higher-level abstractions for working with
The following are higher level operations on mutexes. These are mutexes.
available from
@example
(use-modules (ice-9 threads))
@end example
@deffn macro with-mutex mutex body1 body2 @dots{} @deffn macro with-mutex mutex body1 body2 @dots{}
Lock @var{mutex}, evaluate the body @var{body1} @var{body2} @dots{}, Lock @var{mutex}, evaluate the body @var{body1} @var{body2} @dots{},