zmq_atomic_counter_new.txt 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. zmq_atomic_counter_new(3)
  2. =========================
  3. NAME
  4. ----
  5. zmq_atomic_counter_new - create a new atomic counter
  6. SYNOPSIS
  7. --------
  8. *void *zmq_atomic_counter_new (void);*
  9. DESCRIPTION
  10. -----------
  11. The _zmq_atomic_counter_new_ function creates a new atomic counter. You
  12. can use this in multithreaded applications to do, for example, reference
  13. counting of shared objects. The atomic counter is at least 32 bits large.
  14. This function uses platform specific atomic operations.
  15. RETURN VALUE
  16. ------------
  17. The _zmq_atomic_counter_new()_ function returns the new atomic counter
  18. if successful. Otherwise it returns NULL.
  19. EXAMPLE
  20. -------
  21. .Test code for atomic counters
  22. ----
  23. void *counter = zmq_atomic_counter_new ();
  24. assert (zmq_atomic_counter_value (counter) == 0);
  25. assert (zmq_atomic_counter_inc (counter) == 0);
  26. assert (zmq_atomic_counter_inc (counter) == 1);
  27. assert (zmq_atomic_counter_inc (counter) == 2);
  28. assert (zmq_atomic_counter_value (counter) == 3);
  29. assert (zmq_atomic_counter_dec (counter) == 1);
  30. assert (zmq_atomic_counter_dec (counter) == 1);
  31. assert (zmq_atomic_counter_dec (counter) == 0);
  32. zmq_atomic_counter_set (counter, 2);
  33. assert (zmq_atomic_counter_dec (counter) == 1);
  34. assert (zmq_atomic_counter_dec (counter) == 0);
  35. zmq_atomic_counter_destroy (&counter);
  36. return 0;
  37. ----
  38. SEE ALSO
  39. --------
  40. linkzmq:zmq_atomic_counter_set[3]
  41. linkzmq:zmq_atomic_counter_inc[3]
  42. linkzmq:zmq_atomic_counter_dec[3]
  43. linkzmq:zmq_atomic_counter_value[3]
  44. linkzmq:zmq_atomic_counter_destroy[3]
  45. AUTHORS
  46. -------
  47. This page was written by the 0MQ community. To make a change please
  48. read the 0MQ Contribution Policy at <http://www.zeromq.org/docs:contributing>.