Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,5 @@
MyMutex=CreateMutex()
Result = TryLockMutex(MyMutex)
LockMutex(MyMutex)
UnlockMutex(MyMutex)
FreeMutex(MyMutex)

View file

@ -0,0 +1,34 @@
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
Protected a, b
For a = 1 To 3
LockMutex(Mutex)
; Without Lock-/UnLockMutex() here the output from the parallel threads would be all mixed.
; Reading/Writing to shared memory resources are a common use for Mutextes i PureBasic
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