The problem is simple, but I believe the solution (if one exists) is quite complicated. Anyhow, I am currently developing a distributed application which is supposed to implement simple transaction processing (PRINT, ADD, SLEEP, ASSIGN etc.) in parallel by the use of threads (I am using Pthreads for this assignment). As expected, I had a problem with deadlocks occurring when trying to process multiple conflicting transactions (which can be an amount as high as 20) simultaneously.
Now, I have decided to implement a number of retries for the transaction processing of each thread which is basically generated randomly using srand(time(NULL))
and rand()
called in precisely that sequence. The problem is, when working with multiple transactions (on up to 5 different servers), the numbers match since they are basically generated at the same second in time.
So, my question is, is there a way to completely randomly generate integer numbers not using the time()
function, but something else instead?
Thank you in advance for any help and sorry for the (too) long description.