[concurrency-interest] Starting a Thread within a constructor, what can go wrong?

David Holmes davidcholmes at aapt.net.au
Fri Dec 10 23:05:32 EST 2010

> I am for the best practice of NOT starting a thread within a constructor.
> I also have shown that if I follow a bad practice by starting a thread
> within a constructor then it is safe under simple circumstances (as
> David Holmes mentioned in his second reply).
> However, what I am seeking to do is provide an example that proves
> that is NOT safe (even if it is the last statement in a constructor).

In that context it can only become unsafe (under the assumption that
starting the thread after the constructor would be considered safe) when a
subclass is involved. Else for all other intents and purposes the start()
can be considered to have occurred after the constructor completed.

> I appreciate everybody's help, I'll publish my results and test cases
> with an outside link soon.

Tests to prove the presence of a race condition are notoriously difficult to
write and impossible to write reliably.

David Holmes

> Again, thank you for all the help.
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest

More information about the Concurrency-interest mailing list