[fpc-pascal]Crashes with multithreading

Michael.VanCanneyt at Wisa.be Michael.VanCanneyt at Wisa.be
Mon Dec 11 22:52:04 CET 2000


On Mon, 11 Dec 2000, Nico Erfurth wrote:

> >> 
> >> JM> FPC's heap manager and IO functions (writeln/readln) are *not* thread 
> >> JM> safe. That's probably what's causing the crashes. Add the cmem unit (from 
> >> JM> the "packages" units) as the first unit in your "uses" clause, then 
> >> JM> you're at least safe on the memory management side. You can't use heaptrc 
> >> JM> with it though.
> >> Thank you for such fast reply. But if IO operations not thread safe,
> >> does it means that all file operations also unsafe ?
> 
> > Shortly said: Yes. The only solution for this is to use separate
> > streams in each thread, then it'll work fine.
> 
> The problem is, nothing in FPC is threadsafe, even the TThread-Class 
> itself (InitThreads/DoneThreads).
> The FPC-Team really needs to make the RTL and all other classes 
> threadsafe. Its nearly impossible to trace errors in threaded applications.

That is not entirely true; the Belgian national phone company collects data
from their telephone stations using a multi-threaded Win32 application 
written in FPC. 

After changing the standard memory manager with the memory manager of 
Windows itself the application runs very stable. It is just a matter
of programming it right; there are some small parts that require some
attention (such as file IO) but most of the RTL is thread-safe.

The biggest problems are IOResult and the heap manager.
Avoiding these two makes FPC apps pretty thread-safe.

Which of course doesn't mean we won't work on thread-safety :-)

Michael.





More information about the fpc-pascal mailing list