|QBATOMIC.H(3)||libqb Programmer's Manual||QBATOMIC.H(3)|
The most important usage is reference counting. Using qb_atomic_int_inc() and qb_atomic_int_dec_and_test() makes reference counting a very fast operation.
You must not directly read integers or pointers concurrently accessed by multiple threads, but use the atomic accessor functions instead. That is, always use qb_atomic_int_get() and qb_atomic_pointer_get() for read outs. They provide the necessary synchronization mechanisms like memory barriers to access memory locations concurrently.
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 qb_atomic_int_inc() and qb_atomic_int_dec_and_test().
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 qb_atomic_int_compare_and_exchange() or qb_atomic_pointer_compare_and_exchange() respectively.