Skip to content

Commit f6fa5a3

Browse files
committed
[test] Simplify test_pthread_tls. NFC
- Convert to C - Run in core tests under node.
1 parent d925702 commit f6fa5a3

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

test/pthread/test_pthread_tls.cpp renamed to test/pthread/test_pthread_tls.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
1-
#include <thread>
2-
#include <cstdio>
3-
#include <cassert>
1+
#include <pthread.h>
2+
#include <stdio.h>
3+
#include <assert.h>
44

5-
thread_local int tls;
6-
thread_local struct {
5+
_Thread_local int tls;
6+
_Thread_local struct {
77
int a;
88
double b;
99
} data = {1, 2};
10-
thread_local int array[10];
10+
_Thread_local int array[10];
1111

12-
void thread(void) {
12+
void* thread_main(void* arg) {
1313
++tls;
1414
data.a = 3;
1515
data.b = 4;
1616
assert(tls == 1);
1717
assert(data.a == 3);
1818
assert(data.b == 4);
1919
assert(array[9] == 0);
20+
return NULL;
2021
}
2122

2223
int main(void) {
2324
array[9] = 1337;
24-
std::thread t(thread);
25-
t.join();
25+
pthread_t t;
26+
pthread_create(&t, NULL, thread_main, NULL);
27+
pthread_join(t, NULL);
2628
assert(tls == 0);
2729
assert(data.a == 1);
2830
assert(data.b == 2);

test/test_browser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4068,7 +4068,7 @@ def test_pthread_stack_bounds(self):
40684068

40694069
# Test that real `thread_local` works.
40704070
def test_pthread_tls(self):
4071-
self.btest_exit('pthread/test_pthread_tls.cpp', cflags=['-sPROXY_TO_PTHREAD', '-pthread'])
4071+
self.btest_exit('pthread/test_pthread_tls.c', cflags=['-sPROXY_TO_PTHREAD', '-pthread'])
40724072

40734073
# Test that real `thread_local` works in main thread without PROXY_TO_PTHREAD.
40744074
def test_pthread_tls_main(self):

test/test_core.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2714,6 +2714,11 @@ def test_pthread_tls_dylink(self):
27142714
self.cflags.append('-Wno-experimental')
27152715
self.do_run_in_out_file_test('pthread/test_pthread_tls_dylink.c')
27162716

2717+
@node_pthreads
2718+
@needs_dylink
2719+
def test_pthread_tls(self):
2720+
self.do_runf('pthread/test_pthread_tls.c')
2721+
27172722
@no_modularize_instance('uses global Module objecgt')
27182723
def test_pthread_run_script(self):
27192724
shutil.copy(test_file('pthread/foo.js'), '.')

0 commit comments

Comments
 (0)