Man page - ck_spinlock(3)
Packages contas this manual
- ck_hs_fas(3)
- ck_pr_fence_store_atomic(3)
- ck_ht_entry_key(3)
- ck_bitmap_size(3)
- ck_ht_stat(3)
- ck_pr_xor(3)
- ck_ht_init(3)
- ck_ht_gc(3)
- ck_ring_enqueue_spsc_size(3)
- ck_ht_destroy(3)
- ck_ht_entry_key_set_direct(3)
- ck_pr_add(3)
- ck_pr_load(3)
- ck_ht_entry_set(3)
- ck_ring_capacity(3)
- ck_rhs_put_unique(3)
- ck_epoch_register(3)
- ck_pr_fence_memory(3)
- ck_ht_put_spmc(3)
- ck_bitmap_bts(3)
- ck_rhs_next(3)
- ck_hs_grow(3)
- ck_pr_fence_load_atomic(3)
- ck_pr_fence_atomic_store(3)
- ck_array_buffer(3)
- ck_rhs_gc(3)
- ck_bitmap_clear(3)
- ck_pr_fence_atomic_load(3)
- ck_bitmap_buffer(3)
- ck_ht_next(3)
- ck_bitmap_init(3)
- ck_rhs_count(3)
- ck_epoch_recycle(3)
- ck_hs_iterator_init(3)
- ck_pr_bts(3)
- ck_ring_enqueue_spmc_size(3)
- ck_hs_gc(3)
- ck_ring_dequeue_spmc(3)
- ck_ht_entry_key_set(3)
- ck_ht_reset_spmc(3)
- ck_pr_sub(3)
- ck_ht_entry_value_direct(3)
- ck_ht_reset_size_spmc(3)
- ck_bitmap_reset(3)
- ck_ht_entry_empty(3)
- ck_rhs_stat(3)
- ck_epoch_synchronize(3)
- ck_tflock(3)
- ck_rwlock(3)
- ck_bitmap_union(3)
- ck_rhs_rebuild(3)
- ck_ht_remove_spmc(3)
- ck_pr_inc(3)
- ck_pr_fence_store_load(3)
- ck_rhs_apply(3)
- ck_sequence(3)
- ck_rhs_init(3)
- ck_rhs_remove(3)
- ck_pflock(3)
- ck_epoch_poll(3)
- ck_hs_set(3)
- ck_pr_fence_acquire(3)
- ck_pr_fas(3)
- ck_bitmap_test(3)
- ck_pr_store(3)
- ck_hs_stat(3)
- ck_ring_size(3)
- ck_pr_fence_atomic(3)
- ck_ht_get_spmc(3)
- ck_array_length(3)
- ck_ht_entry_value(3)
- ck_hs_rebuild(3)
- ck_array_put(3)
- ck_array_remove(3)
- ck_ring_init(3)
- ck_ht_entry_key_direct(3)
- ck_hs_get(3)
- ck_pr_btc(3)
- ck_rhs_put(3)
- ck_bitmap_base(3)
- ck_pr_fence_release(3)
- ck_bitmap_bits(3)
- ck_array_deinit(3)
- ck_ht_hash_direct(3)
- ck_hs_remove(3)
- ck_rhs_get(3)
- ck_hs_move(3)
- ck_pr_neg(3)
- ck_hs_put(3)
- ck_pr_btr(3)
- ck_epoch_reclaim(3)
- ck_epoch_begin(3)
- ck_bitmap_set(3)
- ck_hs_next(3)
- ck_epoch_end(3)
- ck_rhs_set(3)
- ck_ring_dequeue_spsc(3)
- ck_cohort(3)
- ck_ring_enqueue_spsc(3)
- ck_ht_set_spmc(3)
- ck_pr_faa(3)
- ck_pr_and(3)
- ck_hs_reset(3)
- ck_hs_reset_size(3)
- ck_pr_cas(3)
- ck_ht_grow_spmc(3)
- ck_array_initialized(3)
- ck_pr_fence_load_depends(3)
- ck_pr_not(3)
- ck_ht_entry_key_length(3)
- ck_spinlock(3)
- ck_rhs_grow(3)
- ck_elide(3)
- ck_hs_destroy(3)
- ck_hs_apply(3)
- ck_epoch_init(3)
- ck_pr_rtm(3)
- ck_epoch_barrier(3)
- ck_ring_enqueue_spmc(3)
- ck_bitmap_next(3)
- ck_ht_iterator_init(3)
- ck_rhs_destroy(3)
- ck_ht_entry_set_direct(3)
- ck_ring_trydequeue_spmc(3)
- ck_ht_count(3)
- ck_hs_init(3)
- ck_pr_barrier(3)
- ck_queue(3)
- ck_pr_stall(3)
- ck_swlock(3)
- ck_rhs_fas(3)
- ck_rhs_reset_size(3)
- ck_epoch_call(3)
- ck_pr(3)
- ck_epoch_unregister(3)
- ck_array_put_unique(3)
- ck_bitmap_iterator_init(3)
- ck_rhs_move(3)
- ck_pr_fence_load_store(3)
- ck_array_commit(3)
- ck_rhs_reset(3)
- ck_pr_fence_load(3)
- ck_hs_count(3)
- ck_hs_put_unique(3)
- ck_ht_hash(3)
- ck_array_init(3)
- ck_rhs_iterator_init(3)
- ck_pr_or(3)
- ck_rwcohort(3)
- ck_pr_dec(3)
- ck_pr_fence_store(3)
- ck_brlock(3)
apt-get install libck-dev
Manual
| ck_spinlock(3) | Library Functions Manual | ck_spinlock(3) |
NAME
ck_spinlock_init,
ck_spinlock_lock,
ck_spinlock_unlock,
ck_spinlock_locked,
ck_spinlock_trylock,
ck_spinlock_anderson_init,
ck_spinlock_anderson_locked,
ck_spinlock_anderson_lock,
ck_spinlock_anderson_unlock,
ck_spinlock_cas_init,
ck_spinlock_cas_locked,
ck_spinlock_cas_lock,
ck_spinlock_cas_lock_eb,
ck_spinlock_cas_trylock,
ck_spinlock_cas_unlock,
ck_spinlock_clh_init,
ck_spinlock_clh_locked,
ck_spinlock_clh_lock,
ck_spinlock_clh_unlock,
ck_spinlock_dec_init,
ck_spinlock_dec_locked,
ck_spinlock_dec_lock,
ck_spinlock_dec_lock_eb,
ck_spinlock_dec_trylock,
ck_spinlock_dec_unlock,
ck_spinlock_fas_init,
ck_spinlock_fas_lock,
ck_spinlock_fas_lock_eb,
ck_spinlock_fas_locked,
ck_spinlock_fas_trylock,
ck_spinlock_fas_unlock,
ck_spinlock_hclh_init,
ck_spinlock_hclh_locked,
ck_spinlock_hclh_lock,
ck_spinlock_hclh_unlock,
ck_spinlock_mcs_init,
ck_spinlock_mcs_locked,
ck_spinlock_mcs_lock,
ck_spinlock_mcs_trylock,
ck_spinlock_mcs_unlock,
ck_spinlock_ticket_init,
ck_spinlock_ticket_locked,
ck_spinlock_ticket_lock,
ck_spinlock_ticket_lock_pb,
ck_spinlock_ticket_trylock,
ck_spinlock_ticket_unlock —
spinlock implementations
LIBRARY
Concurrency Kit (libck, -lck)
SYNOPSIS
#include
<ck_spinlock.h>
ck_spinlock_t spinlock =
CK_SPINLOCK_INITIALIZER;
void
ck_spinlock_init(ck_spinlock_t
*lock);
void
ck_spinlock_lock(ck_spinlock_t
*lock);
void
ck_spinlock_unlock(ck_spinlock_t
*lock);
bool
ck_spinlock_locked(ck_spinlock_t
*lock);
bool
ck_spinlock_trylock(ck_spinlock_t
*lock);
void
ck_spinlock_anderson_init(ck_spinlock_anderson_t
*lock,
ck_spinlock_anderson_thread_t
*slots, unsigned int
count);
bool
ck_spinlock_anderson_locked(ck_spinlock_anderson_t
*lock);
void
ck_spinlock_anderson_lock(ck_spinlock_anderson_t
*lock,
ck_spinlock_anderson_thread_t
**slot);
void
ck_spinlock_anderson_unlock(ck_spinlock_anderson_t
*lock,
ck_spinlock_anderson_thread_t
*slot);
ck_spinlock_cas_t spinlock =
CK_SPINLOCK_CAS_INITIALIZER;
void
ck_spinlock_cas_init(ck_spinlock_cas_t
*lock);
bool
ck_spinlock_cas_locked(ck_spinlock_cas_t
*lock);
void
ck_spinlock_cas_lock(ck_spinlock_cas_t
*lock);
void
ck_spinlock_cas_lock_eb(ck_spinlock_cas_t
*lock);
bool
ck_spinlock_cas_trylock(ck_spinlock_cas_t
*lock);
void
ck_spinlock_cas_unlock(ck_spinlock_cas_t
*lock);
void
ck_spinlock_clh_init(ck_spinlock_clh_t
**lock, ck_spinlock_clh_t
*unowned);
bool
ck_spinlock_clh_locked(ck_spinlock_clh_t
**lock);
void
ck_spinlock_clh_lock(ck_spinlock_clh_t
**lock, ck_spinlock_clh_t
*node);
void
ck_spinlock_clh_unlock(ck_spinlock_clh_t
**node);
ck_spinlock_dec_t spinlock =
CK_SPINLOCK_DEC_INITIALIZER;
void
ck_spinlock_dec_init(ck_spinlock_dec_t
*lock);
bool
ck_spinlock_dec_locked(ck_spinlock_dec_t
*lock);
void
ck_spinlock_dec_lock(ck_spinlock_dec_t
*lock);
void
ck_spinlock_dec_lock_eb(ck_spinlock_dec_t
*lock);
bool
ck_spinlock_dec_trylock(ck_spinlock_dec_t
*lock);
void
ck_spinlock_dec_unlock(ck_spinlock_dec_t
*lock);
ck_spinlock_fas_t spinlock =
CK_SPINLOCK_FAS_INITIALIZER;
void
ck_spinlock_fas_init(ck_spinlock_fas_t
*lock);
void
ck_spinlock_fas_lock(ck_spinlock_fas_t
*lock);
void
ck_spinlock_fas_lock_eb(ck_spinlock_fas_t
*lock);
bool
ck_spinlock_fas_locked(ck_spinlock_fas_t
*lock);
bool
ck_spinlock_fas_trylock(ck_spinlock_fas_t
*lock);
void
ck_spinlock_fas_unlock(ck_spinlock_fas_t
*lock);
void
ck_spinlock_hclh_init(ck_spinlock_hclh_t
**lock,
ck_spinlock_hclh_t
*unowned);
bool
ck_spinlock_hclh_locked(ck_spinlock_hclh_t
**lock);
void
ck_spinlock_hclh_lock(ck_spinlock_hclh_t
**lock,
ck_spinlock_hclh_t
*node);
void
ck_spinlock_hclh_unlock(ck_spinlock_hclh_t
**node);
ck_spinlock_mcs_t spinlock =
CK_SPINLOCK_MCS_INITIALIZER;
void
ck_spinlock_mcs_init(ck_spinlock_mcs_t
**lock);
bool
ck_spinlock_mcs_locked(ck_spinlock_mcs_t
**lock);
void
ck_spinlock_mcs_lock(ck_spinlock_mcs_t
**lock, ck_spinlock_mcs_t
*node);
bool
ck_spinlock_mcs_trylock(ck_spinlock_mcs_t
**lock, ck_spinlock_mcs_t
*node);
void
ck_spinlock_mcs_unlock(ck_spinlock_mcs_t
**lock, ck_spinlock_mcs_t
*node);
ck_spinlock_ticket_t spinlock =
CK_SPINLOCK_TICKET_INITIALIZER;
void
ck_spinlock_ticket_init(ck_spinlock_ticket_t
*lock);
bool
ck_spinlock_ticket_locked(ck_spinlock_ticket_t
*lock);
void
ck_spinlock_ticket_lock(ck_spinlock_ticket_t
*lock);
void
ck_spinlock_ticket_lock_pb(ck_spinlock_ticket_t
*lock, unsigned int
period);
bool
ck_spinlock_ticket_trylock(ck_spinlock_ticket_t
*lock);
void
ck_spinlock_ticket_unlock(ck_spinlock_ticket_t
*lock);
DESCRIPTION
A family of busy-wait spinlock implementations. The ck_spinlock_t implementation is simply a wrapper around the fetch-and-swap (ck_spinlock_fas_t) implementation. The table below provides a summary of the current implementations.
| Namespace | Algorithm | Type | Restrictions | Fair |
´----------------------|-----------------------------|---------------|-------------------------|--------'
ck_spinlock_anderson Anderson Array Fixed number of threads Yes
ck_spinlock_cas Compare-and-Swap Centralized None No
ck_spinlock_clh Craig, Landin and Hagersten Queue Lifetime requirements Yes
ck_spinlock_dec Decrement (Linux kernel) Centralized UINT_MAX concurrency No
ck_spinlock_fas Fetch-and-store Centralized None No
ck_spinlock_hclh Hierarchical CLH Queue Lifetime requirements Yes *
ck_spinlock_mcs Mellor-Crummey and Scott Queue None Yes
ck_spinlock_ticket Ticket Centralized None Yes
* Hierarchical CLH only offers weak fairness for threads accross cluster nodes.
If contention is low and there is no hard requirement for starvation-freedom then a centralized greedy (unfair) spinlock is recommended. If contention is high and there is no requirement for starvation-freedom then a centralized greedy spinlock is recommended to be used with an exponential backoff mechanism. If contention is generally low and there is a hard requirement for starvation-freedom then the ticket lock is recommended. If contention is high and there is a hard requirement for starvation-freedom then the Craig and Landin and Hagersten queue spinlock is recommended unless stack allocation is necessary or NUMA factor is high, in which case the Mellor-Crummey and Scott spinlock is recommended. If you cannot afford O(n) space-usage from array or queue spinlocks but still require fairness under high contention then the ticket lock with proportional back-off is recommended. If NUMA factor is high but prefer a greedy lock, then please see ck_cohort(3).
EXAMPLE
#include <ck_spinlock.h>
#include <stdbool.h>
/*
* Alternatively, the mutex may be initialized at run-time with
* ck_spinlock_init(&mutex).
*/
ck_spinlock_t mutex = CK_SPINLOCK_INITIALIZER;
void
example(void)
{
ck_spinlock_lock(&mutex);
/*
* Critical section.
*/
ck_spinlock_unlock(&mutex);
ck_spinlock_lock_eb(&mutex);
/*
* Critical section.
*/
ck_spinlock_unlock(&mutex);
if (ck_spinlock_trylock(&mutex) == true) {
/*
* Critical section.
*/
ck_spinlock_unlock(&mutex);
}
}
SEE ALSO
Additional information available at http://concurrencykit.org/
| July 26, 2013. |