interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / seed / host / tests / flock.om

76 lines · 1250 bytes Raw Blame History
1note flock fd op (Linux flock, ARM64 syscall 32): an exclusive lock held on one open file blocks a
2note LOCK_EX|LOCK_NB from a second open of the same file in a child (-EWOULDBLOCK, 11); after LOCK_UN
3note the child gets it; shared locks coexist; an unknown op is -EINVAL (22); a closed fd is -EBADF (9).
4text path "flock.tmp"
5global status uchar 4
6fn child want long to int
7fd = fopen path 0 len path 524290 0
8if lt fd 0
9ret 50
10end
11r = flock int fd 6
12if ne r want
13ret 51
14end
15ret 0
16end
17fn waitkid want long to int
18pid = fork
19if lt pid 0
20ret 40
21end
22if eq pid 0
23exit child want
24end
25r = waitpid int pid status 0 len status 0
26if ne r pid
27ret 41
28end
29if or ne get status 0 0 ne get status 1 0
30ret int add 60 ulong get status 1
31end
32ret 0
33end
34fn main to int
35fd = fopen path 0 len path 524866 384
36if lt fd 0
37ret 1
38end
39r = flock int fd 6
40if ne r 0
41ret 2
42end
43k = waitkid neg long 11
44if ne k 0
45ret k
46end
47r = flock int fd 8
48if ne r 0
49ret 3
50end
51k = waitkid 0
52if ne k 0
53ret k
54end
55r = flock int fd 1
56if ne r 0
57ret 4
58end
59s = fopen path 0 len path 524290 0
60r = flock int s 5
61if ne r 0
62ret 5
63end
64r = flock int fd 3
65if ne r neg long 22
66ret 6
67end
68c = fclose int s
69c = fclose int fd
70r = flock int fd 2
71if ne r neg long 9
72ret 7
73end
74r = unlink path 0 len path
75ret int r
76end