public static BinomialDistribution ForCoinFlips(int numberOfCoinFlips) { BinomialDistribution result; RwLock.EnterUpgradeableReadLock(); try { if (!CacheOfCalculatedDistributions.TryGetValue(numberOfCoinFlips, out result)) { RwLock.EnterWriteLock(); try { result = CacheOfCalculatedDistributions[numberOfCoinFlips] = new BinomialDistribution(numberOfCoinFlips); CacheOfCalculatedDistributions[numberOfCoinFlips] = result; } finally { RwLock.ExitWriteLock(); } } } finally { RwLock.ExitUpgradeableReadLock(); } return(result); }
public static BinomialDistribution ForCoinFlips(int numberOfCoinFlips) { BinomialDistribution result; RwLock.EnterUpgradeableReadLock(); try { if (!CacheOfCalculatedDistributions.TryGetValue(numberOfCoinFlips, out result)) { RwLock.EnterWriteLock(); try { result = CacheOfCalculatedDistributions[numberOfCoinFlips] = new BinomialDistribution(numberOfCoinFlips); CacheOfCalculatedDistributions[numberOfCoinFlips] = result; } finally { RwLock.ExitWriteLock(); } } } finally { RwLock.ExitUpgradeableReadLock(); } return result; }