v / vlib / sync / thread_test.v
22 lines · 20 sloc · 485 bytes · 017ace6ea7402430a992aa0820d5e472ebca74c7
Raw
1import sync
2
3fn simple_thread() u64 {
4 tid := sync.thread_id()
5 eprintln('simple_thread thread_id: ${tid.hex()}')
6 return tid
7}
8
9fn test_sync_thread_id() {
10 mtid := sync.thread_id()
11 eprintln('main thread_id: ${sync.thread_id().hex()}')
12 x := spawn simple_thread()
13 y := spawn simple_thread()
14 xtid := x.wait()
15 ytid := y.wait()
16 eprintln('main thread_id: ${sync.thread_id().hex()}')
17 dump(xtid.hex())
18 dump(ytid.hex())
19 assert mtid != xtid
20 assert mtid != ytid
21 assert xtid != ytid
22}
23