[fpc-pascal] Can a library synchronize foreign procedure ?

Michael Schnell mschnell at lumino.de
Wed Feb 12 14:38:06 CET 2014


On 02/12/2014 02:02 PM, Fred van Stappen wrote:
>
> Is is possible for a library to synchronize a procedure form the 
> program who use that library ?
What exactly do you mean by "synchronize".

In the FPC-RTL we have TThread.Synchronize.

This means:
  - Push an event on the Event Queue to have it executed by the Main Thread
  - Have this thread wait until the main thread is done.

Now after calling "Synchronize" the current (worker) thread stops. It 
can last a long time until the main thread is ready to fetch and execute 
the Event. After it did that the worker is freed and goes on running, 
while the main thread fetches the next Event from the queue.

In theory it should be possible to start a thread in a library and do 
the stuff synchronize does.

But as TThread is an Object and Objects are implemented on the heap, I 
suppose that you need synchronized heaps between the library and the 
main program.

AFAIK, there is a way to have a library (if written with fpc) "attach" 
to the main program's heap, but I don't know how this is done.

Another way would be to define the complete Thread object in the main 
program and from there just call normal (flat) functions in the library, 
but I suppose this is not what you intend.

-Michael


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20140212/6285b748/attachment.html>


More information about the fpc-pascal mailing list