I am trying to run network stuff in threads. I dont know if there is a problem here but I am suspecting there is so.
Maybe someone could guide me along the way.
The code does the following;
set up a number of thread that download files. Right now files doesnt exist, but the result is the same.
I have put ; infront of setgadgettext, because threads and gadgets can be a bit picky. The result is the same.
In 70% of cases this works.
In 30% i get freeze of program OR strange different errors like:
[ERROR] Program aborted. (by external library)
[ERROR] Invalid memory access.
Can anyone guide me? Can anyone confirm the behavour? Should I *not* use ReceiveHTTPFile in threads? Is this unsafe?
Code: Select all
InitNetwork()
Procedure thread(i.i)
Repeat
;SetGadgetText(i,"Thread "+Str(i)+": ON")
ReceiveHTTPFile("http://google.com/"+Str(Random(29600)),GetTemporaryDirectory()+Str(Random(29600))+".x")
;SetGadgetText(i,"Thread "+Str(i)+": OFF")
Delay(1)
ForEver
EndProcedure
OpenWindow(0,0,0,640,480,"RECEIVEHTTPFILE THREAD",#PB_Window_ScreenCentered | #PB_Window_SystemMenu)
TextGadget(1,0,0,100,24,"Thread 1: OFF")
TextGadget(2,0,30,100,24,"Thread 2: OFF")
TextGadget(3,0,60,100,24,"Thread 3: OFF")
TextGadget(4,0,90,100,24,"Thread 4: OFF")
CreateThread(@thread(), 1)
CreateThread(@thread(), 2)
CreateThread(@thread(), 3)
CreateThread(@thread(), 4)
Repeat
a=WindowEvent()
Until a=#PB_Event_CloseWindow
