Saturday 11 October 2008

More Semaphores in Redcode

While not as elegant as the solution found by Neo and Roy, the following has the advantage of only requiring one DAT.

semaphore: dat    1
....
reset: mul.ab semaphore, semaphore
wait: djn reset, semaphore
mov.a #0, semaphore
....
signal: mov #1, }sema

The second technique kills waiting processes, then respawns them when signaled.

semaphore: dat    1
....
kill: dat 0
....
wait: djn kill, semaphore
next:
....
signal: mov.a #1, semaphore
add.x semaphore, semaphore
seq.a #1, semaphore
spl next

No comments: