6 void* threadfn(void* nop
)
8 enum nobug_resource_state threadenter
= (enum nobug_resource_state
) nop
;
9 NOBUG_THREAD_ID_SET("thread");
12 RESOURCE_USER_INIT(e
);
13 ECHO ("thread startup");
15 if (threadenter
!= NOBUG_RESOURCE_WAITING
)
17 ECHO ("enter via wait");
18 RESOURCE_WAIT(NOBUG_ON
, t
, "thread", e
)
19 NOBUG_RESOURCE_STATE(NOBUG_ON
, threadenter
, e
);
23 ECHO ("enter direct");
24 RESOURCE_ENTER(NOBUG_ON
, t
, "thread", threadenter
, e
);
27 RESOURCE_LEAVE(NOBUG_ON
, e
);
29 ECHO ("thread finished");
34 NOBUG_THREAD_ID_SET("main");
37 RESOURCE_HANDLE_INIT (t
);
38 RESOURCE_ANNOUNCE(NOBUG_ON
, "type", "test", main
, t
);
40 TEST(resourcethreaded_waiting_waiting
)
43 RESOURCE_USER_INIT(e
);
44 RESOURCE_ENTER(NOBUG_ON
, t
, "main", NOBUG_RESOURCE_WAITING
, e
);
46 ECHO ("create thread");
48 pthread_create (&h
, NULL
, threadfn
, (void*)NOBUG_RESOURCE_WAITING
);
50 pthread_join (h
, NULL
);
51 ECHO ("thread joined");
53 RESOURCE_LEAVE(NOBUG_ON
, e
);
56 TEST(resourcethreaded_waiting_exclusive
)
59 RESOURCE_USER_INIT(e
);
60 RESOURCE_ENTER(NOBUG_ON
, t
, "main", NOBUG_RESOURCE_WAITING
, e
);
62 ECHO ("create thread");
64 pthread_create (&h
, NULL
, threadfn
, (void*)NOBUG_RESOURCE_EXCLUSIVE
);
65 pthread_join (h
, NULL
);
66 ECHO ("thread joined");
68 RESOURCE_LEAVE(NOBUG_ON
, e
);
71 TEST(resourcethreaded_waiting_recursive
)
74 RESOURCE_USER_INIT(e
);
75 RESOURCE_ENTER(NOBUG_ON
, t
, "main", NOBUG_RESOURCE_WAITING
, e
);
77 ECHO ("create thread");
79 pthread_create (&h
, NULL
, threadfn
, (void*)NOBUG_RESOURCE_RECURSIVE
);
80 pthread_join (h
, NULL
);
81 ECHO ("thread joined");
83 RESOURCE_LEAVE(NOBUG_ON
, e
);
86 TEST(resourcethreaded_waiting_shared
)
89 RESOURCE_USER_INIT(e
);
90 RESOURCE_ENTER(NOBUG_ON
, t
, "main", NOBUG_RESOURCE_WAITING
, e
);
92 ECHO ("create thread");
94 pthread_create (&h
, NULL
, threadfn
, (void*)NOBUG_RESOURCE_SHARED
);
95 pthread_join (h
, NULL
);
96 ECHO ("thread joined");
98 RESOURCE_LEAVE(NOBUG_ON
, e
);
104 TEST(resourcethreaded_exclusive_waiting
)
107 RESOURCE_USER_INIT(e
);
108 RESOURCE_ENTER(NOBUG_ON
, t
, "main", NOBUG_RESOURCE_EXCLUSIVE
, e
);
110 ECHO ("create thread");
112 pthread_create (&h
, NULL
, threadfn
, (void*)NOBUG_RESOURCE_WAITING
);
113 pthread_join (h
, NULL
);
114 ECHO ("thread joined");
116 RESOURCE_LEAVE(NOBUG_ON
, e
);
119 TEST(resourcethreaded_exclusive_exclusive
)
122 RESOURCE_USER_INIT(e
);
123 RESOURCE_ENTER(NOBUG_ON
, t
, "main", NOBUG_RESOURCE_EXCLUSIVE
, e
);
125 ECHO ("create thread");
127 pthread_create (&h
, NULL
, threadfn
, (void*)NOBUG_RESOURCE_EXCLUSIVE
);
128 pthread_join (h
, NULL
);
129 ECHO ("thread joined");
131 RESOURCE_LEAVE(NOBUG_ON
, e
);
134 TEST(resourcethreaded_exclusive_recursive
)
137 RESOURCE_USER_INIT(e
);
138 RESOURCE_ENTER(NOBUG_ON
, t
, "main", NOBUG_RESOURCE_EXCLUSIVE
, e
);
140 ECHO ("create thread");
142 pthread_create (&h
, NULL
, threadfn
, (void*)NOBUG_RESOURCE_RECURSIVE
);
143 pthread_join (h
, NULL
);
144 ECHO ("thread joined");
146 RESOURCE_LEAVE(NOBUG_ON
, e
);
149 TEST(resourcethreaded_exclusive_shared
)
152 RESOURCE_USER_INIT(e
);
153 RESOURCE_ENTER(NOBUG_ON
, t
, "main", NOBUG_RESOURCE_EXCLUSIVE
, e
);
155 ECHO ("create thread");
157 pthread_create (&h
, NULL
, threadfn
, (void*)NOBUG_RESOURCE_SHARED
);
158 pthread_join (h
, NULL
);
159 ECHO ("thread joined");
161 RESOURCE_LEAVE(NOBUG_ON
, e
);
167 TEST(resourcethreaded_recursive_waiting
)
170 RESOURCE_USER_INIT(e
);
171 RESOURCE_ENTER(NOBUG_ON
, t
, "main", NOBUG_RESOURCE_RECURSIVE
, e
);
173 ECHO ("create thread");
175 pthread_create (&h
, NULL
, threadfn
, (void*)NOBUG_RESOURCE_WAITING
);
176 pthread_join (h
, NULL
);
177 ECHO ("thread joined");
179 RESOURCE_LEAVE(NOBUG_ON
, e
);
182 TEST(resourcethreaded_recursive_exclusive
)
185 RESOURCE_USER_INIT(e
);
186 RESOURCE_ENTER(NOBUG_ON
, t
, "main", NOBUG_RESOURCE_RECURSIVE
, e
);
188 ECHO ("create thread");
190 pthread_create (&h
, NULL
, threadfn
, (void*)NOBUG_RESOURCE_EXCLUSIVE
);
191 pthread_join (h
, NULL
);
192 ECHO ("thread joined");
194 RESOURCE_LEAVE(NOBUG_ON
, e
);
197 TEST(resourcethreaded_recursive_recursive
)
200 RESOURCE_USER_INIT(e
);
201 RESOURCE_ENTER(NOBUG_ON
, t
, "main", NOBUG_RESOURCE_RECURSIVE
, e
);
203 ECHO ("create thread");
205 pthread_create (&h
, NULL
, threadfn
, (void*)NOBUG_RESOURCE_RECURSIVE
);
206 pthread_join (h
, NULL
);
207 ECHO ("thread joined");
209 RESOURCE_LEAVE(NOBUG_ON
, e
);
212 TEST(resourcethreaded_recursive_shared
)
215 RESOURCE_USER_INIT(e
);
216 RESOURCE_ENTER(NOBUG_ON
, t
, "main", NOBUG_RESOURCE_RECURSIVE
, e
);
218 ECHO ("create thread");
220 pthread_create (&h
, NULL
, threadfn
, (void*)NOBUG_RESOURCE_SHARED
);
221 pthread_join (h
, NULL
);
222 ECHO ("thread joined");
224 RESOURCE_LEAVE(NOBUG_ON
, e
);
230 TEST(resourcethreaded_shared_waiting
)
233 RESOURCE_USER_INIT(e
);
234 RESOURCE_ENTER(NOBUG_ON
, t
, "main", NOBUG_RESOURCE_SHARED
, e
);
236 ECHO ("create thread");
238 pthread_create (&h
, NULL
, threadfn
, (void*)NOBUG_RESOURCE_WAITING
);
239 pthread_join (h
, NULL
);
240 ECHO ("thread joined");
242 RESOURCE_LEAVE(NOBUG_ON
, e
);
245 TEST(resourcethreaded_shared_exclusive
)
248 RESOURCE_USER_INIT(e
);
249 RESOURCE_ENTER(NOBUG_ON
, t
, "main", NOBUG_RESOURCE_SHARED
, e
);
251 ECHO ("create thread");
253 pthread_create (&h
, NULL
, threadfn
, (void*)NOBUG_RESOURCE_EXCLUSIVE
);
254 pthread_join (h
, NULL
);
255 ECHO ("thread joined");
257 RESOURCE_LEAVE(NOBUG_ON
, e
);
260 TEST(resourcethreaded_shared_recursive
)
263 RESOURCE_USER_INIT(e
);
264 RESOURCE_ENTER(NOBUG_ON
, t
, "main", NOBUG_RESOURCE_SHARED
, e
);
266 ECHO ("create thread");
268 pthread_create (&h
, NULL
, threadfn
, (void*)NOBUG_RESOURCE_RECURSIVE
);
269 pthread_join (h
, NULL
);
270 ECHO ("thread joined");
272 RESOURCE_LEAVE(NOBUG_ON
, e
);
275 TEST(resourcethreaded_shared_shared
)
278 RESOURCE_USER_INIT(e
);
279 RESOURCE_ENTER(NOBUG_ON
, t
, "main", NOBUG_RESOURCE_SHARED
, e
);
281 ECHO ("create thread");
283 pthread_create (&h
, NULL
, threadfn
, (void*)NOBUG_RESOURCE_SHARED
);
284 pthread_join (h
, NULL
);
285 ECHO ("thread joined");
287 RESOURCE_LEAVE(NOBUG_ON
, e
);
290 RESOURCE_FORGET(NOBUG_ON
, t
);