Title: | Boost Mutex Functionality in R |
---|---|
Description: | Boost mutex functionality in R. |
Authors: | Michael J. Kane [aut, cre] |
Maintainer: | Michael J. Kane <[email protected]> |
License: | LGPL-2 | Apache License 2.0 |
Version: | 1.3.10 |
Built: | 2024-12-06 06:29:57 UTC |
Source: | CRAN |
Attach to an existing mutex using either a file or description object
attach.mutex(obj, ...) ## S4 method for signature 'character' attach.mutex(obj, ...) ## S4 method for signature 'boost.mutex.descriptor' attach.mutex(obj, ...)
attach.mutex(obj, ...) ## S4 method for signature 'character' attach.mutex(obj, ...) ## S4 method for signature 'boost.mutex.descriptor' attach.mutex(obj, ...)
obj |
the descriptor object. |
... |
other arguments needed by attach. |
A mutex.
This function creates a boost.mutex
object.
boost.mutex(sharedName = NULL, timeout = NULL, create = TRUE)
boost.mutex(sharedName = NULL, timeout = NULL, create = TRUE)
sharedName |
The name of the shared resource corresponding to the mutex. By default a universal unique identifier is supplied. |
timeout |
The amount of time (in seconds) that the mutex should try to attempt to get a lock. By default no timeout is supplied and the mutex will attempt to acquire the lock indefinitely. |
create |
Should the mutex be created or are we attaching to an
existing on. Default is |
# Create a boost.mutex object with default resource name and no timeout. x = boost.mutex() rm(x) gc()
# Create a boost.mutex object with default resource name and no timeout. x = boost.mutex() rm(x) gc()
Objects of class description allow users to “attach” to existing mutexes within or across processes.
description
the list of description information.
The information required to “attach” to an existing mutex object.
## S4 method for signature 'boost.mutex' describe(x)
## S4 method for signature 'boost.mutex' describe(x)
x |
the boost mutex object to describe. |
Retrieve the list of description information from a descriptor object.
description(x) ## S4 method for signature 'descriptor' description(x)
description(x) ## S4 method for signature 'descriptor' description(x)
x |
the descriptor object. |
a list of description information.
Objects of class description allow users to “attach” to existing mutexes within or across processes.
description
the list of description information.
The is.timed
function tells if a boost.mutex
object has a timeout. The timeout
function tells how long a mutex
will wait for a timeout.
is.timed(m) ## S4 method for signature 'boost.mutex' is.timed(m)
is.timed(m) ## S4 method for signature 'boost.mutex' is.timed(m)
m |
a |
is.timed
returns TRUE
if the object has a timeout and
FALSE
otherwise. If a timeout has been set timeout
returns
the number of seconds a boost.mutex
object will attempt to acquire
a lock and NULL
otherwise.
x = boost.mutex(timeout=5) y = boost.mutex() print(is.timed(x)) print(is.timed(y)) print(timeout(x)) print(timeout(y))
x = boost.mutex(timeout=5) y = boost.mutex() print(is.timed(x)) print(is.timed(y)) print(timeout(x)) print(timeout(y))
The lock
and unlock
functions allow a user to
specify exclusive or shared access to a resource.
lock(m, ...) lock.shared(m, ...) unlock(m, ...) unlock.shared(m, ...)
lock(m, ...) lock.shared(m, ...) unlock(m, ...) unlock.shared(m, ...)
m |
a mutex. |
... |
options associated with the mutex being used including
|
A call to lock
gives exclusive access to a resource; no other
mutex may acquire a lock. A call to to lock.shared
allows other
mutexes to acquire a shared lock on the resource. When shared lock is
called while a exclusive lock has been acquired, the shared lock will
block until the exclusive lock is release. Likewise, if an exclusive lock
is called while a shared lock has been acquired, the exclusive lock will
block until the shared lock is released.
The function returns TRUE
if the lock is successfully
called and FALSE
otherwise.
m = boost.mutex() lock(m) # Some code that needs to be synchronized... unlock(m)
m = boost.mutex() lock(m) # Some code that needs to be synchronized... unlock(m)
This function creates an identifier that will be (with high probability) unique on a single machine or group of machines.
uuid()
uuid()
A unique string.
print(uuid())
print(uuid())