[infinispan-dev] deadlock detection - coin toss

Manik Surtani manik at jboss.org
Thu Jul 9 06:54:43 EDT 2009


On 8 Jul 2009, at 18:39, Jason T. Greene wrote:

> Random is definitely thread-safe in the Sun derived JVMs, and  
> probably thread-safe in other JVMs. I would just use that.
>
> Otherwise you could implement MT:
> http://en.wikipedia.org/wiki/Mersenne_twister

Here's an MT Java impl that claims to be 1.5x faster than  
java.util.Random... :-)

	http://www.cs.gmu.edu/~sean/research/

Otherwise you could impl multiply-with-carry, which is supposed to be  
2x faster than MT, with higher quality randomness.  Here's a python  
impl:

	http://code.activestate.com/recipes/576707/

>
> Mircea Markus wrote:
>> this is regarding: http://tinyurl.com/nunmyu
>> In order to be able to determine which tx should commit and which  
>> will rollback, I need to generate a coin toss for each node - a  
>> random number.
>> In order to do that I'm thinking to use on of the following:
>> 1) use java.util.Random . The issue with this class is that it has  
>> an undocumented behavior when it comes to concurrent access, so I  
>> cannot rely on it behaving correctly if  I don't  enforce proper  
>> synchronization. I'm afraid this might become a bottleneck as all  
>> the prepapares requests might want to synchronize on it.
>> 2) Another approach would be to build an Random instance for each  
>> call. I made a test an the performance cost of new Random() +  
>> Random.nextLong is about 4 times bigger than call of  
>> random.nextLong only (on my laptop only), still about 15 mils for  
>> 1k creations
>> 3) use System.nanos. Even though the conflicting tx are created at  
>> the same time, the chance for it to happen in the same nanosecond  
>> is very small, I would say. Don't know how this works for all  
>> architectures, though...
>> Any feedback much welcomed!
>> Cheers,
>> Mircea
>> _______________________________________________
>> infinispan-dev mailing list
>> infinispan-dev at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/infinispan-dev
>
>
> -- 
> Jason T. Greene
> JBoss, a division of Red Hat
> _______________________________________________
> infinispan-dev mailing list
> infinispan-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/infinispan-dev

--
Manik Surtani
manik at jboss.org
Lead, Infinispan
Lead, JBoss Cache
http://www.infinispan.org
http://www.jbosscache.org







More information about the infinispan-dev mailing list