Code just locks up but does not crash.
Every other command I've used in a semaphore so far has had no problem and all works as expected.
I've put some sample code together to demonstrate the issue.
Code: Select all
Global Window_0
Global Image_0, Button_0, Button_1, Button_2, Picture_0, index
Global filename.s = "D:\Program Files\PureBasic 5.22 x64\Examples\Sources\Data\PureBasicLogo.bmp"
Global testMutex = CreateMutex()
Global testSemaphore = CreateSemaphore()
Procedure testProblem(junk.l)
Shared testMutex, testSemaphore, Picture_0, Image_0, filename
LockMutex(testMutex)
LoadImage(Picture_0, filename)
SetGadgetState(Image_0, ImageID(Picture_0))
a = 2 + 2
UnlockMutex(testMutex)
SignalSemaphore(testSemaphore)
EndProcedure
Procedure OpenWindow_0(x = 0, y = 0, width = 600, height = 400)
Window_0 = OpenWindow(#PB_Any, x, y, width, height, "Semaphore Test", #PB_Window_SystemMenu)
Image_0 = ImageGadget(#PB_Any, 10, 10, 580, 320, 0, #PB_Image_Border)
Button_0 = ButtonGadget(#PB_Any, 10, 340, 180, 50, "Load Image (Main Thread)", #PB_Button_MultiLine)
Button_1 = ButtonGadget(#PB_Any, 210, 340, 180, 50, "Clear Image")
Button_2 = ButtonGadget(#PB_Any, 410, 340, 180, 50, "Load Image (Semaphore)", #PB_Button_MultiLine)
EndProcedure
Procedure Window_0_Events(event)
Select event
Case #PB_Event_CloseWindow
ProcedureReturn #False
Case #PB_Event_Menu
Select EventMenu()
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case Button_0
LoadImage(Picture_0, filename)
SetGadgetState(Image_0, ImageID(Picture_0))
Case Button_1
SetGadgetState(Image_0, 0)
Case Button_2
For index = 1 To 10
If CreateThread(@testProblem(), 0)
WaitSemaphore(testSemaphore)
Debug "index = " + Str(index)
EndIf
Next index
EndSelect
EndSelect
ProcedureReturn #True
EndProcedure
OpenWindow_0()
While Window_0_Events(WaitWindowEvent()) : Delay(1): Wend
Code: Select all
SetGadgetState(Image_0, ImageID(Picture_0))
I'm use 5.22LTS on Windows 8.1 x64 using the x86 compiler with thread safe enabled.