|
NAME
LIBRARYConcurrency Kit (libck, -lck) SYNOPSIS
void
void
bool
void
void
void
bool
void
DESCRIPTIONBig reader locks are distributed reader-writer locks with low latency constant time reader acquisition (with respect to number of concurrent readers). On the other hand, writer acquisitions are a relatively expensive O(n) operation. This is a write-biased lock. EXAMPLEstatic ck_brlock_t lock = CK_BRLOCK_INITIALIZER;
static __thread ck_brlock_reader_t reader;
static void
reader(void)
{
/* Add our thread as a lock participant. */
ck_brlock_read_register(&lock, &reader);
for (;;) {
ck_brlock_read_lock(&lock, &reader);
/* Read-side critical section. */
ck_brlock_read_unlock(&reader);
if (ck_brlock_read_trylock(&lock, &reader, 1) == true) {
/* Read-side critical section. */
ck_brlock_read_unlock(&reader);
}
}
return;
}
static void
writer(void)
{
for (;;) {
ck_brlock_write_lock(&lock);
/* Write-side critical section. */
ck_brlock_write_unlock(&lock);
if (ck_brlock_write_trylock(&lock, 1) == true) {
/* Write-side critical section. */
ck_brlock_write_unlock(&lock);
}
}
return;
}
SEE ALSOAdditional information available at http://concurrencykit.org/
|