Problem with Threads (v3.94 beta2)

Linux specific forum
Mowen
User
User
Posts: 48
Joined: Tue Oct 07, 2003 1:04 pm
Location: Belgium

Problem with Threads (v3.94 beta2)

Post by Mowen »

I use Threads in an application developed for Windows and Linux. The one on the Windows version works very well. On the Linux version, the application freezes itself and sometimes crashes. The code is identical between both versions.
The source of the problem seems to be when you call an external function from the Thread procedure. Here is a sample:

Code: Select all

Procedure MyOtherFunction()
   ...
EndProcedure

Procedure MyThreadFunction(Param)
   ...
   MyOtherFunction() 
   ...
EndProcedure

...
ThreadId = CreateThread(@MyThreadFunction(), 0)
....
It works better when I desactivate the calling to MyOtherFunction(). It could be a stack problem when using Threads in the Linux version ?
I will try to give later a more complete code sample to illustrate.
PureBasic: one of the best programming tools ever ! PB is light, easy, crossplatform, powerfull, fast, extendable, enjoyable and... tasty ;-)
Fred
Administrator
Administrator
Posts: 18350
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

Could you try to use ProcedureCDLL as declaration for your tread procedure on linux and see if there is a difference ?
Mowen
User
User
Posts: 48
Joined: Tue Oct 07, 2003 1:04 pm
Location: Belgium

Post by Mowen »

No improvement using ProcedureCDLL.

But this code works well:

Code: Select all

Procedure MyOtherFunction()
  Debug "MyOtherFunction"
EndProcedure

Procedure MyThreadFunction(Param)
  Repeat
    MyOtherFunction()
    Delay(1000)
  ForEver
EndProcedure

ThreadId = CreateThread(@MyThreadFunction(), 0)
Debug ThreadId
Delay(10000)
Debug "End"
End
I manipulate Linked Lists and Gadgets in the procedure I call from the Thread procedure. Maybe the problem is there. Also I call this procedure outside the thread and it works well.
PureBasic: one of the best programming tools ever ! PB is light, easy, crossplatform, powerfull, fast, extendable, enjoyable and... tasty ;-)
Fred
Administrator
Administrator
Posts: 18350
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

Yes, the linked lists aren't thread safe (they have a global pointer).
Mowen
User
User
Posts: 48
Joined: Tue Oct 07, 2003 1:04 pm
Location: Belgium

Post by Mowen »

Yes but it works with the Windows version. I know both OS are completly different (memory management) and it is difficult to guarantee the full compatibility in different situations.
PureBasic: one of the best programming tools ever ! PB is light, easy, crossplatform, powerfull, fast, extendable, enjoyable and... tasty ;-)
Post Reply