Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
30
Task/Mutex/Shale/mutex.shale
Normal file
30
Task/Mutex/Shale/mutex.shale
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
#!/usr/local/bin/shale
|
||||
|
||||
thread library // POSIX threads, mutexes and semaphores
|
||||
time library // We use its sleep function here.
|
||||
|
||||
// The threead code which will lock the mutex, print a message,
|
||||
// then unlock the mutex.
|
||||
threadCode dup var {
|
||||
arg dup var swap =
|
||||
|
||||
stop lock thread::()
|
||||
arg "Thread %d has the mutex\n" printf
|
||||
stop unlock thread::()
|
||||
} =
|
||||
|
||||
stop mutex thread::() // Create the mutex.
|
||||
stop lock thread::() // Lock it until we've started the threads.
|
||||
|
||||
// Now create a few threads that will also try to lock the mutex.
|
||||
1 threadCode create thread::()
|
||||
2 threadCode create thread::()
|
||||
3 threadCode create thread::()
|
||||
4 threadCode create thread::()
|
||||
// The threads are all waiting to acquire the mutex.
|
||||
|
||||
"Main thread unlocking the mutex now..." println
|
||||
stop unlock thread::()
|
||||
|
||||
// Wait a bit to let the threads do their stuff.
|
||||
1000 sleep time::() // milliseconds
|
||||
Loading…
Add table
Add a link
Reference in a new issue