Mutex: Difference between revisions
Content added Content deleted
(Omit from Factor) |
|||
Line 288: | Line 288: | ||
end |
end |
||
end</lang> |
end</lang> |
||
=={{header|PureBasic}}== |
|||
PureBasic has the following Mutex functions; |
|||
<lang PureBasic>MyMutex=CreateMutex() |
|||
Result = TryLockMutex(MyMutex) |
|||
LockMutex(MyMutex) |
|||
UnlockMutex(MyMutex) |
|||
FreeMutex(MyMutex)</lang> |
|||
'''Example''' |
|||
<lang PureBasic>Declare ThreadedTask(*MyArgument) |
|||
Define Mutex |
|||
If OpenConsole() |
|||
Define thread1, thread2, thread3 |
|||
Mutex = CreateMutex() |
|||
thread1 = CreateThread(@ThreadedTask(), 1): Delay(5) |
|||
thread2 = CreateThread(@ThreadedTask(), 2): Delay(5) |
|||
thread3 = CreateThread(@ThreadedTask(), 3) |
|||
WaitThread(thread1) |
|||
WaitThread(thread2) |
|||
WaitThread(thread3) |
|||
PrintN(#CRLF$+"Press ENTER to exit"): Input() |
|||
FreeMutex(Mutex) |
|||
CloseConsole() |
|||
EndIf |
|||
Procedure ThreadedTask(*MyArgument) |
|||
Shared Mutex |
|||
Define a, b |
|||
For a = 1 To 3 |
|||
LockMutex(Mutex) |
|||
PrintN("Thread "+Str(*MyArgument)+": Print 3 numbers in a row:") |
|||
For b = 1 To 3 |
|||
Delay(75) |
|||
PrintN("Thread "+Str(*MyArgument)+" : "+Str(b)) |
|||
Next |
|||
UnlockMutex(Mutex) |
|||
Next |
|||
EndProcedure</lang> |
|||
=={{header|Ruby}}== |
=={{header|Ruby}}== |