Sign in Join

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

Mailing lists / fpc-pascal / 2018-06

Multiple thread heaps

9 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

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

Terry Mead

If the default memory manager for FP creates a heap for each thread, what happens if an object is created in one thread and freed by another ? Also, do calls to New () allocate space on the thread heap or just allocated by the OS ?

---
This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus

Sven Barth
to Terry Mead

Terry Mead schrieb am So., 17. Juni 2018, 07:45:

If the default memory manager for FP creates a heap for each thread, what happens if an object is created in one thread and freed by another ?

If I remember correctly the memory becomes part of the thread's free list that freed the memory. (Though I could be wrong here)

Also, do calls to New () allocate space on the thread heap or just

allocated by the OS ?

All Pascal memory functions are handled by the heap manager. So yes, it's the thread's heap.

Regards,
Sven

Florian Klämpfl
to Sven Barth: Terry Mead schrieb am So., 17. Juni 2018, 07:45: If I remember correctly the memory…
Sven Barth wrote 8 lines
Terry Mead < > schrieb am So., 17. Juni 2018, 07:45: If the default memory manager for FP creates a heap for each thread, what happens if an object is created in one thread and freed by another ? If I remember correctly the memory becomes part of the thread's free list that freed the memory. (Though I could be wrong here)

No. It is added to the "wait for free" queue of the thread which initially allocated it.

Sven Barth
to Florian Klämpfl

Florian Klämpfl schrieb am So., 17. Juni 2018,
10:47:

Show quoted text 16 lines
Am 17.06.2018 um 09:44 schrieb Sven Barth via fpc-pascal: > Terry Mead < > schrieb am So., 17. Juni 2018, 07:45: > > If the default memory manager for FP creates a heap for each thread, what happens if an object is created in one > thread and freed by another ? > > > If I remember correctly the memory becomes part of the thread's free list that freed the memory. (Though I could be > wrong here) No. It is added to the "wait for free" queue of the thread which initially allocated it.

Ah! That's how it was! 🤦‍♀️

Regards,
Sven

Florian Klämpfl
to Fabio Luis Girardi
Fabio Luis Girardi wrote 11 lines
Em Dom, 17 de jun de 2018 05:48, Florian Klämpfl < > escreveu: No. It is added to the "wait for free" queue of the thread which initially allocated it. So, excluding the performance penalty, this is not a problem?

Why should it be a problem?

Terry Mead
to Florian Klämpfl

It is not a problem it just makes it a bit tricky tracking memory usage because of the delay between releasing the memory and it the reported heap usage decreasing.  I haven't had a good look at the source but maybe there is some way to take these pending releases into account. Thanks for your input.

Florian Klämpfl wrote 20 lines
Am 17.06.2018 um 16:40 schrieb Fabio Luis Girardi: > > > Em Dom, 17 de jun de 2018 05:48, Florian Klämpfl > < > escreveu: > > > >     No. It is added to the "wait for free" queue of the thread which > initially allocated it. > > > > So, excluding the performance penalty, this is not a problem? Why should it be a problem? _______________________________________________ fpc-pascal maillist  -  http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

---
This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus

Florian Klämpfl
to Terry Mead
Terry Mead wrote
It is not a problem it just makes it a bit tricky tracking memory usage because of the delay between releasing the memory and it the reported heap usage decreasing.

Just install your own heap manager which is a wrapper around the current one and track allocations/deallocations. FPC does not do this because these values have no real meaning on a multi threaded/multi process system and because it must be done by atomic operations which slow down things.

I haven't had a good look at the source but maybe there is some way to take these pending releases into account.