Is it neccessary to create a placeholder lock object to for thread-safety (and correctness) or is it sufficient to lock on the resource itself (assuming no other code will need it).
locking a System.Random
private static readonly Random rnd = new Random();
public static int Rand(int min, int max) {
lock(rnd) {
return rnd.Next(min, max);
}
}
using a separate placeholder/dummy lock object
private static readonly Random rnd = new Random();
private static readonly object rndLock = new object()
public static int Rand(int min, int max) {
lock(rndLock) {
return rnd.Next(min, max);
}
}
this may seem trivial but i'm concerned with if the first code-block is susceptible to deadlock or other issues