Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2001-06

RTL thread safety

4 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Matti Hamalainen

What parts of the RTL are NOT thread safe and why?

I.e. what should I avoid if I want to create
a threaded program with FPC?

Well, this may be a too big on to answer,
but shoot me ;-)

=- ccr/TNSP^pWp
] | http://www.tnsp.org/
] Show me your "realtime raytracer in Java"
] and I'll show you my CBM 8032, 2 MHz!

Michael Van Canneyt
to Matti Hamalainen
Matti Hamalainen wrote
What parts of the RTL are NOT thread safe and why?

Heap management and standard IO (read/write).
Why ? because they use and modify global variables/structures.

heap management is not yet possible to solve, standard IO can be solved by using the sysutils functions FileRead/FileWrite etc.

Show quoted text 6 lines
I.e. what should I avoid if I want to create a threaded program with FPC? Well, this may be a too big on to answer, but shoot me ;-)

It is not too big, but the answer is not simple either.

Michael.

Peter Vreman
Show quoted text 8 lines
What parts of the RTL are NOT thread safe and why? I.e. what should I avoid if I want to create a threaded program with FPC? Well, this may be a too big on to answer, but shoot me ;-)

At least the Heapmanager and IO. So no classes and objects creation etc. becuase they use the heap.

The reason why they are not thread safe is very simple... NO TIME!

Matti Hamalainen
to Michael Van Canneyt: Heap management and standard IO (read/write). Why ? because they use and modify global…
Michael Van Canneyt wrote 7 lines
> What parts of the RTL are NOT thread safe and why? Heap management and standard IO (read/write). Why ? because they use and modify global variables/structures. heap management is not yet possible to solve, standard IO can be solved by using the sysutils functions FileRead/FileWrite etc.

So, if I use IO only in non-threaded modules and allocate memory similarly, I should be on relatively safe ground?

(Actually, this is how my library is currently (mostly) implemented. Might need to do some checking though. :I )

It is not too big, but the answer is not simple either.

Thanks for answering to my stupid questions :)

=- ccr/TNSP^pWp
] | http://www.tnsp.org/
] Show me your "realtime raytracer in Java"
] and I'll show you my CBM 8032, 2 MHz!