#import "std/thread"
#import "std/sync"
mutex: Mutex;
main :: fn () s32 {
print("Start thread!!!\n");
defer print("Threads joined!!!\n");
mutex_init(&mutex);
defer mutex_terminate(&mutex);
t1 :: thread_create(&first);
t2 :: thread_create(&second);
thread_join(t1);
thread_join(t2);
return 0;
}
first :: fn (args: *u8) s32 {
loop i := 0; i < 10; i += 1 {
mutex_lock(&mutex);
print("Hello from first thread!\n");
mutex_unlock(&mutex);
os_sleep_ms(50.0);
}
return 0;
}
second :: fn (args: *u8) s32 {
loop i := 0; i < 10; i += 1 {
mutex_lock(&mutex);
print("Hello from second thread!\n");
mutex_unlock(&mutex);
os_sleep_ms(100.0);
}
return 0;
}