This method creates a thread and runs the blk of code passed to it.
This method creates a thread and runs the blk of code passed to it. It is used since constructors in java are not re-entrant accross threads so if two different threads grab two different enum elements very close to each other in time, a deadlock can occur since CEnum.this.getClass will end up calling the constructors of all the member enum elements. And, in this (atleast) one of those constructors will be blocked in another thread on the result of CEnum.this.getClass.
Thread1: EnumElementA Base Trait Ctor Begins Thread2: EnumElementB Base Trait Ctor Begins either makes it to the call CEnum.this.getClass add(EnumElementA) get's called, if this is thread1 ok (since the ctor was called there) otherwise this will block since no instance of A is constructed yet. This block will then be a deadlock, since the add cannot complete and hence the CEnum derived class cannot complete construction.
This code works around all that by making a separate thread that does initialization. The ordinal method will busy block until the ordinal is set.
On ScalaJS this works around issues with parent obj vs contained object initialization order