GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
ck_rwlock(3) FreeBSD Library Functions Manual ck_rwlock(3)

ck_rwlock_init, ck_rwlock_write_lock, ck_rwlock_write_unlock, ck_rwlock_write_trylock, ck_rwlock_write_downgrade, ck_rwlock_locked_writer, ck_rwlock_read_lock, ck_rwlock_read_trylock, ck_rwlock_read_unlock, ck_rwlock_locked_reader, ck_rwlock_recursive_write_lock, ck_rwlock_recursive_write_trylock, ck_rwlock_recurisve_write_unlock, ck_rwlock_recursive_read_lock, ck_rwlock_recursive_read_trylock, ck_rwlock_recursive_read_unlock
centralized write-biased reader-writer locks

Concurrency Kit (libck, -lck)

#include <ck_rwlock.h>

ck_rwlock_t lock = CK_RWLOCK_INITIALIZER;


void
ck_rwlock_init(ck_rwlock_t *lock);

void
ck_rwlock_write_lock(ck_rwlock_t *lock);

void
ck_rwlock_write_unlock(ck_rwlock_t *lock);

bool
ck_rwlock_write_trylock(ck_rwlock_t *lock);

bool
ck_rwlock_write_downgrade(ck_rwlock_t *lock);

bool
ck_rwlock_locked_writer(ck_rwlock_t *lock);

void
ck_rwlock_read_lock(ck_rwlock_t *lock);

bool
ck_rwlock_read_trylock(ck_rwlock_t *lock);

void
ck_rwlock_read_unlock(ck_rwlock_t *lock);

bool
ck_rwlock_locked_reader(ck_rwlock_t *lock);

ck_rwlock_recursive_t lock = CK_RWLOCK_RECURSIVE_INITIALIZER;


void
ck_rwlock_recursive_write_lock(ck_rwlock_recursive_t *lock, unsigned int tid);

bool
ck_rwlock_recursive_write_trylock(ck_rwlock_recursive_t *lock, unsigned int tid);

void
ck_rwlock_recurisve_write_unlock(ck_rwlock_recursive_t *lock);

void
ck_rwlock_recursive_read_lock(ck_rwlock_recursive_t *lock);

bool
ck_rwlock_recursive_read_trylock(ck_rwlock_recursive_t *lock);

void
ck_rwlock_recursive_read_unlock(ck_rwlock_recursive_t *lock);

This is a centralized write-biased reader-writer lock. It requires very little space overhead and has a low latency fast path. Write-side recursion requires usage of ck_rwlock_recursive. Read-side recursion is disallowed. The ck_rwlock_write_downgrade() function degrades the caller's write-side acquisition to a read-side acquisition without forfeit of current critical section.

#include <ck_rwlock.h>

static ck_rwlock_t lock = CK_RWLOCK_INITIALIZER;

static void
reader(void)
{

	for (;;) {
		ck_rwlock_read_lock(&lock);
		/* Read-side critical section. */
		ck_rwlock_read_unlock(&lock);

		if (ck_rwlock_read_trylock(&lock) == true) {
			/* Read-side critical section. */
			ck_rwlock_read_unlock(&lock);
		}
	}

	return;
}

static void
writer(void)
{

	for (;;) {
		ck_rwlock_write_lock(&lock);
		/* Write-side critical section. */
		ck_rwlock_write_unlock(&lock);

		if (ck_rwlock_write_trylock(&lock, 1) == true) {
			/* Write-side critical section. */
			ck_rwlock_write_unlock(&lock);
		}
	}

	return;
}

ck_brlock(3), ck_elide(3)

Additional information available at http://concurrencykit.org/

July 26, 2013.

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.