[fpc-devel] Suggestion: reference counted objects
giuliano.colla at fastwebnet.it
Tue Sep 23 11:11:08 CEST 2014
Il 22/09/2014 23:04, Boian Mitov ha scritto:
> If you are experienced in parallel processing, you should know the
> This is a huge topic, and I have done number of sessions on some
> aspects of it, but here will give you a small example (again this is
> just a small example).
> You have a data object that needs to be processed by 600 threads, and
> when they all have consumed(finished with it) it, it needs to be
> With ref counting you create the object send it to all threads, each
> thread has its own reference to the object.
> When they all release the references the object is destroyed.
I agree with you that parallel processing is a very huge topic, but just
because of that I strongly disagree with your assumption that what can
be good for a very specific kind of application is good for every
In addition to the observations of Marco, I can give you a small
You have a number of threads creating thousands of data objects, which
should be processed by "consumer" threads. Creating threads are unaware
of how data will be used (it may depend on active options, and it
follows the golden rule of "reusable code") so they can't send those
objects anywhere. Therefore pointers to those objects are inserted in a
A "consumer" thread can either process a data object, and then dispose
of it, or leave it in the list for further processing, or move it to a
different list, again depending on the selected options.
This scheme can apply to quite a number of applications, from data
collected in a real-time process to data-base transactions, etc.
However you attempt to apply reference counting in this scheme, you'll
realize that either it doesn't work at all, or it forces you to add a
considerable amount of code, whose purpose would be only to fool
reference counting, and artificially increase or decrease reference count.
The same applies to your example, if it happens that when creating your
data object you don't know which threads will consume it, because
threads are created dynamically (captors activated and deactivated,
options enabled/disabled, users connecting and disconnecting, etc).
More information about the fpc-devel