1CK_EPOCH_SYNCHRONIZE(3)  BSD Library Functions Manual  CK_EPOCH_SYNCHRONIZE(3)
2

NAME

4     ck_epoch_synchronize — block until a grace period has been detected
5

LIBRARY

7     Concurrency Kit (libck, -lck)
8

SYNOPSIS

10     #include <ck_epoch.h>
11
12     void
13     ck_epoch_synchronize(ck_epoch_record_t *record);
14

DESCRIPTION

16     The ck_epoch_synchronize(3) function will block the caller until a grace
17     period has been detected, according to the semantics of epoch reclama‐
18     tion.  Any objects requiring safe memory reclamation which are logically
19     deleted are safe for physical deletion following a call to
20     ck_epoch_synchronize(3).  If you require that all callbacks be dis‐
21     patched, then it is suggested that you use ck_epoch_barrier(3) instead or
22     follow a call of ck_epoch_synchronize(3) with ck_epoch_reclaim(3).
23

EXAMPLE

25           #include <ck_epoch.h>
26           #include <ck_stack.h>
27           #include <stdlib.h>
28
29           /*
30            * epoch was previously initialized with ck_epoch_init.
31            * stack was previously initialized with ck_stack_init.
32            */
33           ck_epoch_t *epoch;
34           ck_stack_t *stack;
35
36           void
37           function(void)
38           {
39                   ck_epoch_record_t *record;
40                   ck_stack_entry_t *s;
41
42                   record = malloc(sizeof *record);
43                   ck_epoch_register(&epoch, record);
44
45                   /*
46                    * We are using an epoch section here to guarantee no
47                    * nodes in the stack are deleted while we are dereferencing
48                    * them. This is needed here because there are multiple writers.
49                    * If there was only one thread popping from the this stack,
50                    * then there is no need to ck_epoch_begin/ck_epoch_end.
51                    */
52                   ck_epoch_begin(record);
53
54                   /* Logically delete an object. */
55                   s = ck_stack_pop_upmc(stack);
56
57                   ck_epoch_end(record);
58
59                   /*
60                    * Wait until no threads could possibly have a reference to the
61                    * object we just popped (assume all threads are simply executing
62                    * ck_stack_pop_upmc).
63                    */
64                   ck_epoch_synchronize(record);
65
66                   /* It is now safe to physically delete the object. */
67                   free(s);
68                   return;
69           }
70

RETURN VALUES

72     This function has no return value.
73

ERRORS

75     The object pointed to by .Fa record must have been previously registered
76     via ck_epoch_register(3).
77

SEE ALSO

79     ck_epoch_init(3), ck_epoch_register(3), ck_epoch_unregister(3),
80     ck_epoch_recycle(3), ck_epoch_poll(3), ck_epoch_reclaim(3),
81     ck_epoch_barrier(3), ck_epoch_call(3), ck_epoch_begin(3), ck_epoch_end(3)
82
83     Additional information available at http://concurrencykit.org/
84
85                               September 2, 2012
Impressum