In that code snippet, the call to gc() is stand in for other code which could trigger a gc. And it is also possible that this other code alters the coordination stack (fails the coordination; coordination times out; ...), so the pop() call may not return the coordination began in the first line.
 
So one really does need to keep the began coordination in a local variable to ensure you are attempting to end the same coordination you began. That is, the code snippet is broken in multiple ways.
--

BJ Hargrave
Senior Technical Staff Member, IBM // office: +1 386 848 1781
OSGi Fellow and CTO of the OSGi Alliance // mobile: +1 386 848 3788
[email protected]
 
 
----- Original message -----
From: [email protected]
Sent by: [email protected]
To: "OSGi Developer Mail List" <[email protected]>
Cc:
Subject: Re: [osgi-dev] Valid coordinator scenario?
Date: Mon, Aug 3, 2015 3:37 PM
 
To me this is less bad than having the coordination hang around for who-
knows- how- long in a ThreadLocal (or similar), but tastes may vary.

> I've created an OSGi issue to clarify whether below snippet is supposed
> to always work and after discussing this with BJ, that code is bound to
> fail as there is no strong reference to the coordination. The spec and
> the CT hint that the thread local (or equivalent construct) which holds
> the coordination in the implementation must be a weak reference.
> Therefore with the example below, no one is holding a strong reference
> to the coordination which then allows it to be garbage collected.
>
> Regards
> Carsten
>
> Am 31.07.15 um 04:48 schrieb Carsten Ziegeler:
>> Hi,
>>
>> Christian brought up an interesting scenario for using the coordinator.
>> The question is, if the following is a valid scenario:
>>
>>    coordinator.begin("test", 0);
>>    System.gc();
>>    coordinator.pop().end();
>>
>> (Of course no one will do a gc() call in his code, its just for
>> demonstrational purposes)
>>
>> The coordination is bound to the thread, but no reference is held.
>>
>> Should the coordination be garbage collected? Looking at the CT it
>> seems, the answer is yes.
>>
>> Regards
>> Carsten
>>
>
>
> --
> Carsten Ziegeler
> Adobe Research Switzerland
> [email protected]
> _______________________________________________
> OSGi Developer Mail List
> [email protected]
> https://mail.osgi.org/mailman/listinfo/osgi-dev
>


_______________________________________________
OSGi Developer Mail List
[email protected]
https://mail.osgi.org/mailman/listinfo/osgi-dev

 

_______________________________________________
OSGi Developer Mail List
[email protected]
https://mail.osgi.org/mailman/listinfo/osgi-dev

Reply via email to