.\" Automatically generated man page, do not edit .TH QBATOMIC.H 3 2023-07-21 "LIBQB" "libqb Programmer's Manual" .SH NAME qbatomic.h \- Basic atomic integer and pointer operations. .SH SYNOPSIS .nf .B #include .SH DESCRIPTION .PP The following functions can be used to atomically access integers and pointers. They are implemented as inline assembler function on most platforms and use slower fall-backs otherwise. Using them can sometimes save you from using a performance-expensive pthread_mutex to protect the integer or pointer. .PP The most important usage is reference counting. Using \fIqb_atomic_int_inc()\fR and \fIqb_atomic_int_dec_and_test()\fR makes reference counting a very fast operation. .PP You must not directly read integers or pointers concurrently accessed by multiple threads, but use the atomic accessor functions instead. That is, always use \fIqb_atomic_int_get()\fR and \fIqb_atomic_pointer_get()\fR for read outs. They provide the necessary synchronization mechanisms like memory barriers to access memory locations concurrently. .PP If you are using those functions for anything apart from simple reference counting, you should really be aware of the implications of doing that. There are literally thousands of ways to shoot yourself in the foot. So if in doubt, use a pthread_mutex. If you don't know, what memory barriers are, do not use anything but \fIqb_atomic_int_inc()\fR and \fIqb_atomic_int_dec_and_test()\fR. .PP It is not safe to set an integer or pointer just by assigning to it, when it is concurrently accessed by other threads with the following functions. Use \fIqb_atomic_int_compare_and_exchange()\fR or \fIqb_atomic_pointer_compare_and_exchange()\fR respectively. .SH SEE ALSO .PP .nh .ad l \fIqb_atomic_int_set\fR(3), \fIqb_atomic_int_compare_and_exchange\fR(3), \fIqb_atomic_int_get\fR(3), \fIqb_atomic_int_add\fR(3), \fIqb_atomic_init\fR(3), \fIqb_atomic_pointer_get\fR(3), \fIqb_atomic_int_exchange_and_add\fR(3), \fIqb_atomic_pointer_compare_and_exchange\fR(3), \fIqb_atomic_pointer_set\fR(3) .ad .hy .SH "COPYRIGHT" .PP Copyright (C) 2003 Sebastian Wilhelmi