Page 1 of 1
1 Thread = 1 Procedure?!
Posted: Sat Apr 26, 2003 10:59 am
by Kendrel
i have recently played around with threads, and i wonder if it is possible to have two threads using the same procedure.
i have tried it on my own, but either i was drunk or made some stupid mistakes
a little code snippet which could help me get started would be really nice if this is possible.

Posted: Sat Apr 26, 2003 11:29 am
by Pupil
Yes it's possible to have two threads use the same procedure, but you have to be aware that if you're using global variables inside the procedures you can't predict the result, particulary if you write to these variables inside the procedures. Another thing to look out for is if you use string handling inside your threaded procedures, at this time none(i believe) of the string commands is thread safe..
I believe there's some example of how to do threads here on the forum, just do a search...
Posted: Sat Apr 26, 2003 12:58 pm
by Danilo
Code: Select all
;
; by Danilo, 08.03.2003 (de-forum)
;
Global FensterZahl
Procedure FensterThread(value)
FensterZahl + 1
OpenWindow(FensterZahl, Random(300), Random(300), 200, 200, #PB_Window_MinimizeGadget, "Fenster "+Str(FensterZahl))
Repeat
Select WaitWindowEvent()
Case #PB_EventCloseWindow
QuitThread = 1
EndSelect
Until QuitThread = 1
EndProcedure
If OpenWindow(0, 0, 0, 150, 100, #PB_Window_MinimizeGadget|#PB_Window_ScreenCentered, "Hauptfenster")
CreateGadgetList(WindowID())
#Button1 = 1:ButtonGadget(#Button1, 0, 0, 150, 21, "Neues Fenster erstellen")
Repeat
Select WaitWindowEvent()
Case #PB_EventGadget
Select EventGadgetID() ;Gadgets
Case #Button1 ;ButtonGadget
CreateThread(@FensterThread(),0)
EndSelect ;EventGadgetID()
Case #PB_EventCloseWindow
Quit = 1
EndSelect ;Event
Until Quit = 1
End
EndIf