Page 1 of 1

Problem with Threads (v3.94 beta2)

Posted: Wed Aug 31, 2005 10:22 am
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.

Posted: Wed Aug 31, 2005 10:28 am
by Fred
Could you try to use ProcedureCDLL as declaration for your tread procedure on linux and see if there is a difference ?

Posted: Wed Aug 31, 2005 12:06 pm
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.

Posted: Thu Sep 01, 2005 2:36 am
by Fred
Yes, the linked lists aren't thread safe (they have a global pointer).

Posted: Fri Sep 02, 2005 9:38 am
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.