oz_(un)protect() API unsafe

David Hopwood david.nospam.hopwood at blueyonder.co.uk
Sat Feb 10 21:08:41 CET 2007


Denys Duchier wrote:
> Raphael Collet <raph at info.ucl.ac.be> writes:
> 
>>Denys, this is unclear to me, too.  Could you please explain the problem, and
>>the proposed fix?
> 
> I am thinking in terms of a little itch I am scratching involving pthreads.  It
> will usually be the case that tasks delegated to pthreads will need to hold on
> to some Oz data structure, if only to have a way to return a result or indicate
> termination etc...  They will therefore need to OZ_protect it on initiation and
> OZ_unprotect it on termination.  If it turns out that 2 tasks need to hold on to
> the same Oz data structure, the first one to terminate will OZ_unprotect the
> data and that data may well be garbage collected before the second task
> terminates.
> 
> The fix is simply to add a counter to each protected data: the counter is
> incremented by oz_protect and decremented by oz_unprotect.  You would only really
> unlink the data from the protected list if the counter reaches 0.

It needs to be an atomic counter, I think.

-- 
David Hopwood <david.nospam.hopwood at blueyonder.co.uk>



More information about the mozart-hackers mailing list