1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
//! Description of the optional `sync_point` macro.
/// Create a named code synchronization point.
/// It is required in order to combine two or more synchronized places in the code,
/// excluding their simultaneous execution.
///
/// ### 1. One named sync point and two or more sync codes for it.
/// ```rust
/// use synchronized::sync_point;
/// use synchronized::sync;
///
/// sync_point! {(COMB_SYNC) {
/// static mut POINT: usize = 0;
///
/// // #1 Anonymous synchronized code that operates on a single named synchronization point.
/// let result0 = sync! ((->COMB_SYNC) {
/// unsafe {
/// POINT += 1;
///
/// POINT
/// }
/// });
///
/// // This line of code is not synchronized and can run concurrently on all threads.
/// println!("Unsynchronized code");
///
/// // #2 Anonymous synchronized code that operates on a single named synchronization point.
/// let result1 = sync! ((->COMB_SYNC) {
/// unsafe {
/// POINT += 1;
///
/// POINT
/// }
/// });
/// }}
/// ```
///
/// ### 2. One named sync point and two or more sync codes for it. With one mutable variable.
/// ```rust
/// use synchronized::sync;
/// use synchronized::sync_point;
///
/// sync_point! {COMB_SYNC (String = String::new()) {
/// static mut POINT: usize = 0;
///
/// // #1 Anonymous synchronized code that operates on a single named synchronization point.
/// let result0 = sync! ((->COMB_SYNC) {
/// unsafe {
/// POINT += 1;
///
/// POINT
/// }
/// });
///
/// // #1 This line of code is not synchronized and can run concurrently on all threads.
/// println!("Unsynchronized code");
///
/// // Synchronized code by `COMB_SYNC` label with `sync_let: String` mutable variable
/// let result1 = sync!(->COMB_SYNC(sync_let) {
/// // sync_let <-- String (COMB_SYNC)
/// *sync_let = "test".to_string();
/// });
///
/// // #2 This line of code is not synchronized and can run concurrently on all threads.
/// println!("Unsynchronized code");
///
/// // #2 Anonymous synchronized code that operates on a single named synchronization point.
/// let result2 = sync! ((->COMB_SYNC) {
/// unsafe {
/// POINT += 1;
///
/// POINT
/// }
/// });
/// }}
=> ;
=> ;
=> ;
=> ;
=>
}