To continue the discussion on this topic (stemming from issue 11635) I’m 
starting a new thread. Please share your thoughts.

From the other thread:

> Also open for discussion is the use of Collection>>randomForPicking and 
> Collection>>mutexForPicking in other methods (such as #atRandom). I think it 
> shouldn't be too big a problem to make those methods use individual Random 
> instances and to remove the two class variables from Collection.

#randomForPicking answers a Random stored in a class variable. Access to this 
variable is protected by a Mutext stored in a class variable 
(#mutexForPicking). The problem, as revealed by issue 11635, is of course that 
you have to know that you may only use that Random object if you also protect 
access to it with the class side Mutex. Otherwise race conditions can occur. 
#atRandom is one prominent user of #randomForPicking and #mutexForPicking.

Henrik’s thoughts:

> As for #atRandom using Random new, the performance hit and seed quality would 
> be much greater concerns, as the Random instance would only be used once per 
> invocation.
> At this point in time there's no good alternatives to the current approach, 
> but renaming the mutex/shared variable to reflect its singular use would be 
> one possible improvement, I guess.

So one possibility would be rename these methods, for example to #atRandomMutex 
and #atRandomRandom (no, I haven’t given much thought to the names :) ).

Max

Reply via email to