Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
55
Task/Mutex/M2000-Interpreter/mutex.m2000
Normal file
55
Task/Mutex/M2000-Interpreter/mutex.m2000
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
Form 80, 50
|
||||
Module CheckIt {
|
||||
Thread.Plan Concurrent
|
||||
Class mutex {
|
||||
mylock as boolean=True
|
||||
Function Lock {
|
||||
if not .mylock then exit
|
||||
.mylock<=False
|
||||
=True
|
||||
}
|
||||
Module Unlock {
|
||||
.mylock<=True
|
||||
}
|
||||
}
|
||||
Group PhoneBooth {
|
||||
NowUser$
|
||||
module UseIt (a$, x){
|
||||
.NowUser$<=a$
|
||||
Print a$+" phone home ",Int(x*100);"%"
|
||||
}
|
||||
module leave {
|
||||
.NowUser$<=""
|
||||
}
|
||||
}
|
||||
m=mutex()
|
||||
Flush
|
||||
Data "Bob", "John","Tom"
|
||||
For i=1 to 3 {
|
||||
Thread {
|
||||
\\ we use N$, C and Max as stack variables for each thread
|
||||
\\ all other variables are shared for module
|
||||
If C=0 Then if not m.lock() then Print N$+" waiting...................................":Refresh 20: Continue
|
||||
C++
|
||||
if c=1 then thread this interval 20
|
||||
PhoneBooth.UseIt N$,C/Max
|
||||
iF C<Max Then Continue
|
||||
PhoneBooth.leave
|
||||
m.Unlock
|
||||
Thread This Erase
|
||||
} as K
|
||||
Read M$
|
||||
Thread K Execute Static N$=M$, C=0, Max=RANDOM(5,8)
|
||||
Thread K interval Random(300, 2000)
|
||||
}
|
||||
\\ Start we lock Phone Booth for service
|
||||
Service=m.lock()
|
||||
Main.Task 50 {
|
||||
If Service Then if Keypress(32) then m.unlock: Service=false: Continue
|
||||
If not Service then if Keypress(32) Then if m.lock() then Service=true : Continue
|
||||
if PhoneBooth.NowUser$<>"" Then {
|
||||
Print "Phone:";PhoneBooth.NowUser$: Refresh
|
||||
} Else.if Service then Print "Service Time": Refresh
|
||||
}
|
||||
}
|
||||
CheckIt
|
||||
Loading…
Add table
Add a link
Reference in a new issue