Mutex Execution Locks
Posted: Thu Feb 22, 2007 4:48 am
Why does this eventually lockup?
Regards
Code: Select all
#Red1=$0000FF ;red
#Gray1=$D4D4D4 ;grey
Global Mutex1=CreateMutex()
MainWindow = OpenWindow(0,0,0,800,600,"",#PB_Window_TitleBar|#PB_Window_SystemMenu)
PImage = CreateImage(1,700, 500)
If MainWindow=0 Or CreateGadgetList(WindowID(0))=0:MessageRequester("Error","OpenWindow Error",0) :End: EndIf
PRDrawing = ImageGadget(1, 40, 85,700,500,PImage,#PB_Image_Border)
Procedure DoLoop()
For a =1 To 100000
LockMutex(Mutex1)
ApiDC=StartDrawing(ImageOutput(1)) ;api commands need apiDC
Box(0,0,40,40,#Red1) ; and draw it
StopDrawing()
Debug "mutex Proc "+Str(a)
SetGadgetState(1, ImageID(1))
UnlockMutex(Mutex1)
Next
EndProcedure
Thread =CreateThread(@DoLoop(),#Null)
Repeat
Event=WaitWindowEvent()
If Event = #PB_Event_CloseWindow ; If the user has pressed on the close button
KillThread(Thread)
Break
EndIf
LockMutex(Mutex1)
ApiDC=StartDrawing(ImageOutput(1))
Box(0,0,40,40,#Gray1) ; and draw it
StopDrawing()
Debug "mutex Main"
SetGadgetState(1, ImageID(1))
UnlockMutex(Mutex1)
ForEver