zmq_atomic_counter_inc.txt 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. zmq_atomic_counter_inc(3)
  2. =========================
  3. NAME
  4. ----
  5. zmq_atomic_counter_inc - increment an atomic counter
  6. SYNOPSIS
  7. --------
  8. *int zmq_atomic_counter_inc (void *counter);*
  9. DESCRIPTION
  10. -----------
  11. The _zmq_atomic_counter_inc_ function increments an atomic counter in a
  12. threadsafe fashion. This function uses platform specific atomic
  13. operations.
  14. RETURN VALUE
  15. ------------
  16. The _zmq_atomic_counter_inc()_ function returns the old value of the
  17. counter, before incrementing.
  18. EXAMPLE
  19. -------
  20. .Test code for atomic counters
  21. ----
  22. void *counter = zmq_atomic_counter_new ();
  23. assert (zmq_atomic_counter_value (counter) == 0);
  24. assert (zmq_atomic_counter_inc (counter) == 0);
  25. assert (zmq_atomic_counter_inc (counter) == 1);
  26. assert (zmq_atomic_counter_inc (counter) == 2);
  27. assert (zmq_atomic_counter_value (counter) == 3);
  28. assert (zmq_atomic_counter_dec (counter) == 1);
  29. assert (zmq_atomic_counter_dec (counter) == 1);
  30. assert (zmq_atomic_counter_dec (counter) == 0);
  31. zmq_atomic_counter_set (counter, 2);
  32. assert (zmq_atomic_counter_dec (counter) == 1);
  33. assert (zmq_atomic_counter_dec (counter) == 0);
  34. zmq_atomic_counter_destroy (&counter);
  35. return 0;
  36. ----
  37. SEE ALSO
  38. --------
  39. linkzmq:zmq_atomic_counter_new[3]
  40. linkzmq:zmq_atomic_counter_set[3]
  41. linkzmq:zmq_atomic_counter_dec[3]
  42. linkzmq:zmq_atomic_counter_value[3]
  43. linkzmq:zmq_atomic_counter_destroy[3]
  44. AUTHORS
  45. -------
  46. This page was written by the 0MQ community. To make a change please
  47. read the 0MQ Contribution Policy at <http://www.zeromq.org/docs:contributing>.