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


_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to