[concurrency-interest] Exposing self-references in constructors
Ryan.LeCompte at pango.com
Wed Dec 20 17:43:48 EST 2006
Here is a scenario:
- In Thread A's constructor, a reference to "this" is passed along which ultimately ends up stored as a reference in Thread B.
- Thread A's constructor completes and is fully instantiated.
- Thread B then is later executed (let's say restrained at 30 seconds later) -- and then uses the reference to Thread A that it was given in Thread A's constructor.
Is it possible that Thread B's reference to Thread A could be "stale" ? I'm not seeing that this is the case. I know that it's bad practice to hand off references to yourself before you are fully constructed, but in this paticular case I'd like to know if I'm "safe" if I have external time constraints that force Thread B to not read its reference to Thread A until a later time when Thread A has finished fully instantiating.
Also, what if Thread B is already executing and just operates on a an object instance that contains the reference stored in Thread A's constructor? Consider a scheduling framework where a pool of threads are already instantiated and running, and simply periodically execute "work instances" that contain the logic to be executed.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Concurrency-interest