![]() |
![]()
| ![]() |
![]()
NAME
LIBRARYConcurrency Kit (libck, -lck) SYNOPSIS
unsigned int
bool
void
void
DESCRIPTIONIt is recommended to use ck_sequence when a small amount of data
that cannot be accessed atomically has to be synchronized with readers in a
fashion that does not block any writer. Readers are able to execute their
read-side critical sections without any atomic operations. A ck_sequence_t
must be initialized before use. It may be initialized using either a static
initializer (CK_SEQUENCE_INITIALIZER) or using
EXAMPLE#include <ck_sequence.h> #include <stdlib.h> static struct example { int a; int b; int c; } global; static ck_sequence_t seqlock = CK_SEQUENCE_INITIALIZER; void reader(void) { struct example copy; unsigned int version; /* * Attempt a read of the data structure. If the structure * has been modified between ck_sequence_read_begin and * ck_sequence_read_retry then attempt another read since * the data may be in an inconsistent state. */ do { version = ck_sequence_read_begin(&seqlock); copy = global; } while (ck_sequence_read_retry(&seqlock, version)); /* * The previous may also be expressed using CK_SEQUENCE_READ. * Generally recommend to only use ck_sequence_read_retry * if you would like to detect a conflicting write at some * higher granularity. */ CK_SEQUENCE_READ(&seqlock, &version) { copy = global; } return; } void writer(void) { for (;;) { ck_sequence_write_begin(&seqlock); global.a = rand(); global.b = global.a + global.b; global.c = global.b + global.c; ck_sequence_write_end(&seqlock); } return; } SEE ALSOck_brlock(3), ck_bytelock(3), ck_rwlock(3) Additional information available at http://concurrencykit.org/
|