@@ -36,29 +36,41 @@ run_long_task()
36
36
}
37
37
38
38
void
39
- __wasi_thread_start_C ( int thread_id , int * start_arg )
39
+ start_job ( )
40
40
{
41
- shared_t * data = (shared_t * )start_arg ;
41
+ sem_post (& sem );
42
+ run_long_task (); // Wait to be interrupted
43
+ assert (false && "Unreachable" );
44
+ }
42
45
43
- if (data -> throw_exception ) {
44
- // Wait for all other threads (including main thread) to be ready
45
- printf ("Waiting before terminating\n" );
46
- for (int i = 0 ; i < NUM_THREADS ; i ++ )
47
- sem_wait (& sem );
46
+ void
47
+ terminate_process ()
48
+ {
49
+ // Wait for all other threads (including main thread) to be ready
50
+ printf ("Waiting before terminating\n" );
51
+ for (int i = 0 ; i < NUM_THREADS ; i ++ )
52
+ sem_wait (& sem );
48
53
49
- printf ("Force termination\n" );
54
+ printf ("Force termination\n" );
50
55
#if TEST_TERMINATION_BY_TRAP == 1
51
- __builtin_trap ();
56
+ __builtin_trap ();
52
57
#else
53
- __wasi_proc_exit (1 );
58
+ __wasi_proc_exit (1 );
54
59
#endif
60
+ }
61
+
62
+ void
63
+ __wasi_thread_start_C (int thread_id , int * start_arg )
64
+ {
65
+ shared_t * data = (shared_t * )start_arg ;
66
+
67
+ if (data -> throw_exception ) {
68
+ terminate_process ();
55
69
}
56
70
else {
57
71
printf ("Thread running\n" );
58
72
59
- sem_post (& sem );
60
- run_long_task (); // Wait to be interrupted
61
- assert (false && "Unreachable" );
73
+ start_job ();
62
74
}
63
75
}
64
76
@@ -107,22 +119,13 @@ main(int argc, char **argv)
107
119
return EXIT_FAILURE ;
108
120
}
109
121
110
- printf ("Main thread running\n" );
111
-
112
- sem_post (& sem );
113
-
114
122
#if TEST_TERMINATION_IN_MAIN_THREAD == 1
115
-
116
123
printf ("Force termination (main thread)\n" );
117
- #if TEST_TERMINATION_BY_TRAP == 1
118
- __builtin_trap ();
119
- #else /* TEST_TERMINATION_BY_TRAP */
120
- __wasi_proc_exit (1 );
121
- #endif /* TEST_TERMINATION_BY_TRAP */
122
-
124
+ terminate_process ();
123
125
#else /* TEST_TERMINATION_IN_MAIN_THREAD */
124
- run_long_task (); // Wait to be interrupted
125
- assert (false && "Unreachable" );
126
+ printf ("Main thread running\n" );
127
+
128
+ start_job ();
126
129
#endif /* TEST_TERMINATION_IN_MAIN_THREAD */
127
130
return EXIT_SUCCESS ;
128
131
}
0 commit comments