1 Thread = 1 Procedure?!

Just starting out? Need help? Post your questions and find answers here.
Kendrel
User
User
Posts: 58
Joined: Fri Apr 25, 2003 7:00 pm

1 Thread = 1 Procedure?!

Post 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. :lol:
Pupil
Enthusiast
Enthusiast
Posts: 715
Joined: Fri Apr 25, 2003 3:56 pm

Post 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...
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Post 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
cya,
...Danilo
...:-=< http://codedan.net/work >=-:...
-= FaceBook.com/DaniloKrahn =-
Post Reply