[fpc-pascal] Stack problem in externally called callback function

Wimpie Nortje wimpienortje at gmail.com
Mon Aug 3 08:49:12 CEST 2009

The FPC thread setup code (CAllocateThreadVars, InitThread) happens 
inside the newly created thread before the user's thread function starts.

The only viable way I see to get support from the C library is for it to 
inform FPC about a new thread after creation, but this means that the C 
user's thread function has already started executing when FPC gets the 
new ID. Is it possible to do the FPC thread setup from outside the new 
thread? Suppose this setup can be completed before the library starts 
calling FPC callbacks, would all the current memory problems then be solved?

Jonas Maebe wrote:
> On 02 Aug 2009, at 20:02, Wimpie Nortje wrote:
>> Thanks for the response.
>> The library uses a centralised function to start all its threads 
>> using pthread_create. If I can make this central function inform FPC 
>> about all the threads created, would this work?
> There is no interface in the RTL to inform it about newly created 
> external threads, so it would be quite hard.
>> Assuming it would work:  what information would FPC require? When 
>> would this info be required, before or after thread creation? What 
>> needs to be done on the FPC side with this info?
> Look at rtl/unix/cthreads.pp, in the functions CBeginThread/ThreadMain 
> and CEndThread (they also call generic code from rtl/inc/thread.inc, 
> such as InitThread and DoneThread).
> Jonas
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal

More information about the fpc-pascal mailing list