]> git.saurik.com Git - apple/libdispatch.git/blob - testing/dispatch_sema.c
libdispatch-84.5.5.tar.gz
[apple/libdispatch.git] / testing / dispatch_sema.c
1 #include <dispatch/dispatch.h>
2 #include <pthread.h>
3 #include <stdio.h>
4 #include <assert.h>
5
6 #include "dispatch_test.h"
7
8 #define LAPS 10000
9
10 int
11 main(void)
12 {
13 static size_t total;
14 dispatch_semaphore_t dsema;
15
16 test_start("Dispatch Semaphore");
17
18 dsema = dispatch_semaphore_create(1);
19 assert(dsema);
20
21 dispatch_apply(LAPS, dispatch_get_concurrent_queue(0), ^(size_t idx __attribute__((unused))) {
22 dispatch_semaphore_wait(dsema, DISPATCH_TIME_FOREVER);
23 total++;
24 dispatch_semaphore_signal(dsema);
25 });
26
27 dispatch_release(dsema);
28
29 test_long("count", total, LAPS);
30 test_stop();
31
32 return 0;
33 }