[concurrency-interest] Latches and safe handoff

Dhanji R. Prasanna dhanji at gmail.com
Tue Dec 15 19:00:34 EST 2009

Here is a pattern that I am curious about:

public void doStuff() {

    MyException[] holder = new MyException[1];
    otherThreadPerformer.perform(new Runnable() {
        ... run() {
           try {
           } catch (MyException e) {
              holder[0] = e;
           } finally {
              latch.go(); //can't recall what the method is called

   // read holder[0]

Is this handoff safe? Or am I better off using an AtomicReference? I imagine
that it is not, as the holder array could still be null (there is no
synchronized write to it) after the latch is opened.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20091216/0857e1ac/attachment.html>

More information about the Concurrency-interest mailing list