1 | # spec/ysh-stdlib
|
2 |
|
3 | ## our_shell: ysh
|
4 |
|
5 | #### semaphore
|
6 | source --builtin draft-synch.ysh
|
7 |
|
8 | sema-new (1, &s)
|
9 | fork {
|
10 | sleep 0.5
|
11 | sema-down (s)
|
12 | echo 1
|
13 | }
|
14 | fork {
|
15 | sleep 1
|
16 | sema-down (s)
|
17 | echo 2
|
18 | }
|
19 | fork {
|
20 | sleep 1.5
|
21 | sema-down (s)
|
22 | echo 3
|
23 | }
|
24 | sleep 2
|
25 | echo 4
|
26 | sema-up (s)
|
27 | sleep 0.5
|
28 | echo 5
|
29 | sema-up (s)
|
30 | sema-destroy (s)
|
31 | ## STDOUT:
|
32 | 1
|
33 | 4
|
34 | 2
|
35 | 5
|
36 | 3
|
37 | ## END
|
38 |
|
39 | #### semaphore init and multiple down
|
40 | source --builtin draft-synch.ysh
|
41 |
|
42 | sema-new (3, &s)
|
43 | fork {
|
44 | sleep 1
|
45 | sema-up (s)
|
46 | }
|
47 | sema-down (s)
|
48 | sema-down (s)
|
49 | sema-down (s)
|
50 | sema-down (s)
|
51 | echo yes
|
52 | ## STDOUT:
|
53 | yes
|
54 | ## END
|
55 |
|
56 | # TODO: add test case for mutex and other sync primitives
|