2022-06-29 07:21:35 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <threads.h>
|
|
|
|
#include <stdatomic.h>
|
|
|
|
|
2023-02-18 14:58:56 +00:00
|
|
|
_Thread_local int counter;
|
|
|
|
tss_t key;
|
2022-06-29 07:21:35 +00:00
|
|
|
|
2023-02-18 14:58:56 +00:00
|
|
|
int f(void* thr_data) {
|
|
|
|
tss_set(key, "Thread 2 finished");
|
2023-02-15 09:54:58 +00:00
|
|
|
for(int n = 0; n < 5; ++n)
|
2023-02-18 14:58:56 +00:00
|
|
|
counter++;
|
|
|
|
puts(tss_get(key));
|
2022-06-29 07:21:35 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
2023-02-18 14:58:56 +00:00
|
|
|
tss_create(&key, NULL);
|
|
|
|
// thrd_t thread;
|
|
|
|
// int status = thrd_create(&thread, f, NULL);
|
|
|
|
// if(status == thrd_error) {
|
|
|
|
// puts("Failed creating threads");
|
|
|
|
// }
|
|
|
|
// for(int n = 0; n < 10; ++n) {
|
|
|
|
// counter++;
|
|
|
|
// }
|
|
|
|
tss_set(key, "Thread 1 finished");
|
|
|
|
// int res;
|
|
|
|
// if(thrd_join(thread, &res) == thrd_error) {
|
|
|
|
// puts("Failed waiting on thread");
|
|
|
|
// }
|
|
|
|
puts(tss_get(key));
|
|
|
|
tss_delete(key);
|
2022-06-29 07:21:35 +00:00
|
|
|
}
|