/// <summary> /// Acquires the lock. /// </summary> /// <param name="syncObject">The sync object.</param> /// <returns></returns> public static AutoCS AcquireLock(ICriticalSection syncObject) { AutoCS cs = new AutoCS(syncObject); cs._syncObject.Enter(); return(cs); }
public PiGenerator(int stepsAmount, int timeout, int spinsCount) { StepsAmount = stepsAmount; Timeout = timeout; _criticalSection = new CriticalSection(); _criticalSection.SetSpinCount(spinsCount); }
public static double GetPi(int numberOfThreads, int numberOfSteps, int numberOfSpins, int time, bool isEnter) { Thread[] threads = new Thread[numberOfThreads]; int steps = numberOfSteps; timeout = time; criticalSection = new ICriticalSectionImplementation(numberOfSpins); int iterations = numberOfSteps / numberOfThreads; pi = 0; double step = 1.0 / steps; for (int i = 0; i < numberOfThreads; ++i) { Thread thread = isEnter ? new Thread(CalculateWithEnter) : new Thread(CalculateWithTryEnter); threads[i] = thread; ArgsThread argsThread = new ArgsThread(i * iterations, (i + 1) * iterations, step); thread.Start(argsThread); } for (int i = 0; i < numberOfThreads; ++i) { threads[i].Join(); } return(pi); }
public ThreadIntegration(int iterationNumber, int timeout, int Сount, CSType csType) { _iterationNumber = iterationNumber; _timeout = timeout; _csType = csType; _cs = new AutoResetEventCS(); _cs.SetSpinCount(Сount); }
public PiCalculator(int iterations, int timeout, int spinsCount, string enterMethod) { m_iterations = iterations; m_timeout = timeout; m_enterMethod = enterMethod; m_criticalSection = new AutoResetEventMethod(); m_criticalSection.SetSpinCount(spinsCount); }
public PICalculator(int stepsCount, int timeout, int spinCount, ICriticalSection criticalSection) { m_stepsCount = stepsCount; m_timeout = timeout; m_criticalSection = criticalSection; m_spinCount = spinCount; m_criticalSection.SetSpinCount(spinCount); m_step = 1f / m_stepsCount; }
/// <summary> /// Acquires the lock. /// </summary> /// <param name="syncObject">The sync object.</param> /// <returns></returns> public static AutoCS AcquireLock(ICriticalSection syncObject) { AutoCS cs = new AutoCS(syncObject); cs._syncObject.Enter(); return cs; }
/// <summary> /// Initializes a new instance of the <see cref="AutoCS"/> class. /// </summary> /// <param name="syncObject">The sync object.</param> private AutoCS(ICriticalSection syncObject) { _syncObject = syncObject; }
/// <summary> /// Syncronized CyclicBuffer - upper layer provides mutual exclusion API /// </summary> /// <param name="size"> /// A <see cref="System.Int32"/> /// Size of the buffer /// </param> /// <param name="sectionlock"> /// A <see cref="ICriticalSection"/> /// Crtical section lock to use /// </param> public CyclicBuffer(int size, ICriticalSection sectionlock) { this.sectionlock = sectionlock; Init(size); }
public PiCalculator() { _criticalSection = new CriticalSection(); }
/// <summary> /// Initializes a new instance of the <see cref="AutoCS"/> class. /// </summary> /// <param name="syncObject">The sync object.</param> private AutoCS(ICriticalSection syncObject) { _syncObject = syncObject; }