hi !
i am using ubuntu 16.06 , i have problems with threads when i use repeat until ...
Linux works with thread ?
problems in use threads in linux
- skinkairewalker
- Addict

- Posts: 810
- Joined: Fri Dec 04, 2015 9:26 pm
Re: problems in use threads in linux
Of course 
- skinkairewalker
- Addict

- Posts: 810
- Joined: Fri Dec 04, 2015 9:26 pm
Re: problems in use threads in linux
i am trying this example code to test !infratec wrote:Of course
Code: Select all
OpenConsole("")
Procedure loop(*val)
Global a.i = 0
Repeat
PrintN("loop 1 working")
Delay(500)
Until a = 1
EndProcedure
Procedure loop2(*val)
Global b.i = 0
Repeat
PrintN("HelloWorld")
Delay (1000)
Until b = 1
EndProcedure
CreateThread(@loop(),1)
CreateThread(@loop2(),2)but dont works !!!
when i start this application ... it close in same moment !!!
Re: problems in use threads in linux
If you close the mainthread (process), the threads are stopped.
Code: Select all
OpenConsole("")
Procedure loop(*val)
Global a.i = 0
Repeat
PrintN("loop 1 working")
Delay(500)
Until a = 1
EndProcedure
Procedure loop2(*val)
Global b.i = 0
Repeat
PrintN("HelloWorld")
Delay (1000)
Until b = 1
EndProcedure
CreateThread(@loop(),1)
CreateThread(@loop2(),2)
Repeat
Delay(1000)
ForEverPureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Re: problems in use threads in linux
and remember that Linux and OSX aren't as forgiving as Windows when it comes to doing GUI updates from threads
Im guessing that means PrintN() too!? That was a rude shock to me at first because Windows really is amazingly forgiving in that sense, lol, but I'm glad because what i was doing in Windows was seemingly technically incorrect/not best practice. All GUI updates should be done by the main (message loop) thread, with worker threads telling the main thread what to do, typically using PostEvent with a value => #PB_Event_FirstCustomValue (this works smoothly on Windows, Linux, and OSX)
Code: Select all
EnableExplicit
Enumeration #PB_Event_FirstCustomValue
#UpdateProgress
#UpdateFinished
EndEnumeration
Procedure workerthread(WndId)
Protected progress = 0
Repeat
Delay (20) ;simulate some work
progress + 1
PostEvent(#UpdateProgress,WndId,#PB_Ignore,#PB_Ignore,progress) ;send update msg
Until progress => 100
PostEvent(#UpdateFinished,WndId,#PB_Ignore,#PB_Ignore,0) ;send finish msg
EndProcedure
OpenWindow(0, 0, 0, 640, 80, "Worker-Thread GUI Demo", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ProgressBarGadget(1, 12, 30, 620, 20, 0, 100)
ButtonGadget(2, 1, 1, 50, 20, "Start")
Define Event
Repeat
Event = WaitWindowEvent()
Select Event
Case #UpdateProgress ;worker thread has signaled the main thread to update the progress
SetGadgetState(1, EventData())
Case #UpdateFinished
MessageRequester("Done","Finished!")
Case #PB_Event_Gadget
If EventGadget() = 2 ;Start button
CreateThread(@workerthread(), WindowID(0))
EndIf
EndSelect
Until Event = #PB_Event_CloseWindow- skinkairewalker
- Addict

- Posts: 810
- Joined: Fri Dec 04, 2015 9:26 pm
Re: problems in use threads in linux
thanks answers everyone !!

so , how can i make multi windows communicate among themselves ? ^^
thanks by attention !!
so , how can i make multi windows communicate among themselves ? ^^
thanks by attention !!
Re: problems in use threads in linux
You can't! You have to create all GUI in the mainthread.skinkairewalker wrote:so , how can i make multi windows communicate among themselves ? ^^
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

