fb:porticula NoPaste
Threads und Mutexe - für TPM
Uploader: | PMedia |
Datum/Zeit: | 14.12.2007 03:44:33 |
Dim Shared Zaehler As UInteger
Dim Shared Ende As UInteger
Dim Shared ZaehlerMutex As Any Ptr
Dim Shared ThreadA As Any Ptr
Dim Shared ThreadB As Any Ptr
Dim Shared ThreadC As Any Ptr
sub unser_thread_A()
Do
MutexLock ZaehlerMutex
Zaehler += 5
MutexUnlock ZaehlerMutex
Sleep 1000
Loop Until Ende = 1
end sub
sub unser_thread_B()
Do
MutexLock ZaehlerMutex
Zaehler += 2
MutexUnlock ZaehlerMutex
Sleep 750
Loop Until Ende = 1
end sub
sub unser_thread_C()
Do
MutexLock ZaehlerMutex
Zaehler += 11
MutexUnlock ZaehlerMutex
Sleep 225
Loop Until Ende = 1
end sub
ZaehlerMutex = MutexCreate()
ThreadA = ThreadCreate(@Unser_thread_A)
ThreadB = ThreadCreate(@Unser_thread_B)
ThreadC = ThreadCreate(@Unser_thread_C)
Do
cls
locate 1,1
mutexlock Zaehlermutex
print Zaehler
mutexUnlock ZaehlerMutex
Sleep 100
Loop Until MultiKey(&h01)
Ende = 1
ThreadWait(ThreadC)
ThreadWait(ThreadB)
ThreadWait(ThreadA)
MutexDestroy(Zaehlermutex)