zmq_atomic_counter_set.txt 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. zmq_atomic_counter_set(3)
  2. =========================
  3. NAME
  4. ----
  5. zmq_atomic_counter_set - set atomic counter to new value
  6. SYNOPSIS
  7. --------
  8. *void zmq_atomic_counter_set (void *counter, int value);*
  9. DESCRIPTION
  10. -----------
  11. The _zmq_atomic_counter_set_ function sets the counter to a new value,
  12. in a threadsafe fashion. The largest value that is guaranteed to work
  13. across all platforms is 2^31-1. This function uses platform specific
  14. atomic operations.
  15. RETURN VALUE
  16. ------------
  17. The _zmq_atomic_counter_set()_ function has no return value.
  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_inc[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>.