[fpc-devel] Threading support and C library under Linux/Unix

Daniël Mantione daniel.mantione at freepascal.org
Wed Jun 23 10:18:20 CEST 2010



Op Wed, 23 Jun 2010, schreef Graeme Geldenhuys:

> Op 2010-06-22 15:31, Marco van de Voort het geskryf:
>>
>> Same problem. You still have to interface with the kernel, and it would be
>> incompatible with C libraries that use threads.
>
> Well, if I don't use C libraries (only Object Pascal code), then it should
> still be beneficial. I can then write pure Object Pascal code/applications
> and still have multi-threading support.

It's not just about eliminating libc dependencies. I believe it would be 
beneficial in most cases, even when using C libraries, since the Linux 
kernels does not expose a Posix threads like API, Posix threads are 
emulated. The FPC model is again unlike the Posix model, so you have again 
glue code. Directly calling the kernel would remove this overhead and 
allow for more efficient threading.

The fact that the C libraries you call are written for libpthread does not 
need to be a problem:
- You would not be able to share a variable between
   Pascal and C and have threads in both worlds wait on each other and two
   threads may not be able to call C code at the same time, you would
   need to protect that.
- However, C libraries could safely launch pthread based threads without
   getting in the wheels of Pascal based threads.

Daniël


More information about the fpc-devel mailing list