]>
Commit | Line | Data |
---|---|---|
2546420a A |
1 | #include <pthread.h> |
2 | ||
3 | #include <darwintest.h> | |
4 | ||
5 | #define MAX_THREADS 512 | |
6 | #define THREAD_DEPTH 32 | |
7 | ||
8 | static void * | |
9 | thread(void * arg) | |
10 | { | |
11 | T_LOG("thread %lx here: %d", (uintptr_t)pthread_self(), (int)arg); | |
12 | return (arg); | |
13 | } | |
14 | ||
15 | T_DECL(pthread_bulk_create, "pthread_bulk_create") | |
16 | { | |
17 | void *thread_res; | |
18 | pthread_t t[THREAD_DEPTH]; | |
19 | ||
20 | for (int i = 0; i < MAX_THREADS; i += THREAD_DEPTH) { | |
21 | T_LOG("Creating threads %d..%d\n", i, i + THREAD_DEPTH - 1); | |
22 | for (int j = 0; j < THREAD_DEPTH; j++) { | |
23 | void *arg = (void *)(intptr_t)(i + j); | |
24 | T_QUIET; T_ASSERT_POSIX_ZERO( | |
25 | pthread_create(&t[j], NULL, thread, arg), NULL); | |
26 | } | |
27 | T_LOG("Waiting for threads"); | |
28 | for (int j = 0; j < THREAD_DEPTH; j++) { | |
29 | T_QUIET; T_ASSERT_POSIX_ZERO(pthread_join(t[j], &thread_res), NULL); | |
30 | T_QUIET; T_ASSERT_EQ(i + j, (int)thread_res, "thread return value"); | |
31 | } | |
32 | } | |
33 | } |