Skip to content

Commit 430d663

Browse files
authored
Add some testing of __builtin_thread_pointer. NFC (#26718)
See llvm/llvm-project#117817
1 parent 25feb10 commit 430d663

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

test/wasm_worker/wasm_worker_and_pthread.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ _Atomic pid_t main_tid = 0;
1111
_Atomic pid_t pthread_tid = 0;
1212
_Atomic pid_t worker_tid = 0;
1313

14+
void* _Atomic main_ptr = 0;
15+
void* _Atomic pthread_ptr = 0;
16+
void* _Atomic worker_ptr = 0;
17+
1418
EM_JS(int, am_i_pthread, (), {
1519
return ENVIRONMENT_IS_PTHREAD;
1620
});
@@ -21,8 +25,10 @@ EM_JS(int, am_i_wasm_worker, (), {
2125

2226
void *thread_main(void *arg) {
2327
pthread_tid = gettid();
24-
emscripten_outf("hello from pthread! (tid=%d)", pthread_tid);
28+
pthread_ptr = __builtin_thread_pointer();
29+
emscripten_outf("hello from pthread! (tid=%d) (ptr=%p)", pthread_tid, pthread_ptr);
2530
assert(pthread_tid && pthread_tid > main_tid);
31+
assert(pthread_ptr && pthread_ptr != main_ptr);
2632
assert(am_i_pthread());
2733
assert(!am_i_wasm_worker());
2834
assert(!emscripten_current_thread_is_wasm_worker());
@@ -32,8 +38,10 @@ void *thread_main(void *arg) {
3238

3339
void worker_main() {
3440
worker_tid = gettid();
35-
emscripten_outf("hello from wasm worker! (tid=%d)", worker_tid);
41+
worker_ptr = __builtin_thread_pointer();
42+
emscripten_outf("hello from wasm worker! (tid=%d) (ptr=%p)", worker_tid, worker_ptr);
3643
assert(worker_tid && worker_tid > pthread_tid);
44+
assert(worker_ptr && worker_ptr != pthread_ptr);
3745
assert(!am_i_pthread());
3846
assert(am_i_wasm_worker());
3947
assert(emscripten_current_thread_is_wasm_worker());
@@ -46,7 +54,8 @@ void worker_main() {
4654

4755
int main() {
4856
main_tid = gettid();
49-
emscripten_outf("in main (tid=%d)", main_tid);
57+
main_ptr = __builtin_thread_pointer();
58+
emscripten_outf("in main (tid=%d) (ptr=%p)", main_tid, main_ptr);
5059
assert(main_tid > 0);
5160
pthread_t thread;
5261
pthread_create(&thread, NULL, thread_main, NULL);

0 commit comments

Comments
 (0)