Had a question, though this is not related to Windows
as such. Would appreciate an answer very much, because
it would improve some part of my skills alteast.
If an object needs to be deleted, there are multiple
ways of freeing this object if there is more than one
thread that references it. One way, is to use
reference counting on the object.
As an example, say Object A is something that can be
accessed by multiple threads. Now if we just define a
hold and release function which hands out/releases
reference counts, the one that releases the last
reference frees the object. What if there is also
another requirement that states: References should be
handed out only if the object is say active. If some
external event marked the object inactive, references
should not be handed out. The example in my case is an
IO, and the IO can be say marked inactive because of
an Abort call, and any further references to the IO
should not be handed out to any other thread after the
an abort has been received. Now this means that the
function that hands references should check for the
“state” of the command(which now needs to be
synchronized with the hold and release functions
anywhere the “state” is set) and hand out references
atomically and the release function should indicate
via a return value that the reference count is down to
zero so its time to free the object. Now there are
other conditions also, and this solution starts to get
uglier, because every release is followed by a check
to free. And also making a thread go to sleep to wait
for the reference count to go to zero is not viable,
because of the number of threads that could
potentially sleep in this case. Is there any other
solution that could free these objects when the last
reference is released? One might be garbage
collection, but its not very appealing. I am sure
there will be a better way some of you will be able to
come up with. Any ideas?
Do you Yahoo!?
Yahoo! Small Business - Try our new resources site!
http://smallbusiness.yahoo.com/resources/