Re: Promoting weak pointers

Robert A Duff <bobduff@shell01.TheWorld.com>
Wed, 17 Jun 2009 10:38:51 -0400

          From comp.compilers

Related articles
Promoting weak pointers m.helvensteijn@gmail.com (Michiel Helvensteijn) (2009-06-11)
Re: Promoting weak pointers fset.slb@gmail.com (Scott Burson) (2009-06-15)
Re: Promoting weak pointers andrew@tomazos.com (Andrew Tomazos) (2009-06-16)
Re: Promoting weak pointers m.helvensteijn@gmail.com (Michiel Helvensteijn) (2009-06-16)
Re: Promoting weak pointers m.helvensteijn@gmail.com (Michiel Helvensteijn) (2009-06-16)
Re: Promoting weak pointers m.helvensteijn@gmail.com (Michiel Helvensteijn) (2009-06-17)
Re: Promoting weak pointers bobduff@shell01.TheWorld.com (Robert A Duff) (2009-06-17)
Re: Promoting weak pointers andrew@tomazos.com (Andrew Tomazos) (2009-06-18)
Re: Promoting weak pointers armelasselin@hotmail.com (Armel) (2009-06-19)
Re: Promoting weak pointers dot@dotat.at (Tony Finch) (2009-06-19)
| List of all articles for this month |
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Newsgroups: comp.compilers
Date: Wed, 17 Jun 2009 10:38:51 -0400
Organization: The World Public Access UNIX, Brookline, MA
References: 09-06-047 09-06-055 09-06-057
Keywords: linker, parallel
Posted-Date: 18 Jun 2009 17:34:14 EDT

Michiel Helvensteijn <m.helvensteijn@gmail.com> writes:


> On Jun 16, 12:39 pm, Andrew Tomazos <and...@tomazos.com> wrote:
>> if (my_weak_ptr != NULL)
>> my_weak_ptr->do_something();


> [Now I'm confused, too. This is an ordinary race condition of the kind
> that every parallel program has to handle, and would present the same
> issues no matter what kind of pointer it is. -John]


It seems different, because in this case, the race condition is caused
by the implementation (i.e. the garbage collector), not by the
application.


Say Thread A is doing the above 'if', and Thread B has a pointer X that
points to the same heap object as my_weak_ptr. At the same time as
the above 'if', Thread B sets X to null, and the GC gets triggered
for whatever reason, and the heap object gets collected.


The variable my_weak_ptr is not a shared variable. Thread B didn't
touch it. Thread B didn't touch the heap object, either.
So you wouldn't normally expect to need any locking.


The weak pointer is special, in that it can asynchronously get set to
null, even though no application-level thread modified it. So the
language needs some way to deal with them atomically, and Andrew Tomazos
is suggesting an atomic "convert weak to strong" operation.


Similarly, you could have an operation like "make this weak pointer
strong during the following block of code, then it reverts to weak".


- Bob



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.