]>
git.saurik.com Git - apple/libpthread.git/blob - tests/join.c
8 #include <darwintest.h>
10 #define WAITTIME (100 * 1000)
34 res = pthread_join(p, NULL);
40 T_DECL(join
, "pthread_join",
41 T_META_ALL_VALID_ARCHS(YES
))
49 res
= pthread_create(&p
, NULL
, thread
, param
);
50 T_ASSERT_POSIX_ZERO(res
, "pthread_create");
52 res
= pthread_join(p
, &value
);
53 T_ASSERT_POSIX_ZERO(res
, "pthread_join");
54 T_ASSERT_EQ_PTR(param
, value
, "early join value");
57 res
= pthread_create(&p
, NULL
, thread
, param
);
58 T_ASSERT_POSIX_ZERO(res
, "pthread_create");
61 res
= pthread_join(p
, &value
);
62 T_ASSERT_POSIX_ZERO(res
, "pthread_join");
63 T_ASSERT_EQ_PTR(param
, value
, "late join value");
66 res
= pthread_create_suspended_np(&p
, NULL
, thread
, param
);
67 T_ASSERT_POSIX_ZERO(res
, "pthread_create_suspended_np");
68 kr
= thread_resume(pthread_mach_thread_np(p
));
69 T_ASSERT_EQ_INT(kr
, 0, "thread_resume");
71 res
= pthread_join(p
, &value
);
72 T_ASSERT_POSIX_ZERO(res
, "pthread_join");
73 T_ASSERT_EQ_PTR(param
, value
, "suspended early join value");
76 res
= pthread_create_suspended_np(&p
, NULL
, thread
, param
);
77 T_ASSERT_POSIX_ZERO(res
, "pthread_create_suspended_np");
78 kr
= thread_resume(pthread_mach_thread_np(p
));
79 T_ASSERT_EQ_INT(kr
, 0, "thread_resume");
82 res
= pthread_join(p
, &value
);
83 T_ASSERT_POSIX_ZERO(res
, "pthread_join");
84 T_ASSERT_EQ_PTR(param
, value
, "suspended late join value");
86 // This test is supposed to test joining on the main thread. It's not
87 // clear how to express this with libdarwintest for now.
90 param = pthread_self();
91 res = pthread_create_suspended_np(&p, NULL, thread1, param);
92 T_ASSERT_POSIX_ZERO(res, "pthread_create_suspended_np");
93 res = pthread_detach(p);
94 T_ASSERT_POSIX_ZERO(res, "pthread_detach");
95 kr = thread_resume(pthread_mach_thread_np(p));
96 T_ASSERT_EQ_INT(kr, 0, "thread_resume");
102 thread_stub(__unused
void *arg
)
107 T_DECL(pthread_join_stress
, "pthread_join in a loop")
109 for (int i
= 0; i
< 1000; i
++) {
111 for (int j
= 0; j
< i%16
; j
++){
112 T_QUIET
; T_ASSERT_POSIX_SUCCESS(pthread_create(&th
[j
], NULL
, thread_stub
, NULL
), NULL
);
114 for (int j
= i%16
; j
>= 0; j
--){
115 T_QUIET
; T_ASSERT_POSIX_SUCCESS(pthread_join(th
[j
], NULL
), NULL
);