// IMPORTANT: lock() does not guarantee fairness and is vulnerable to thread starvation private void SetReadAccessIfNeeded() { lock (accessLock) { // Only set read access if we're the first one trying to access this potentially-shared Secret if (accessCounter == 0) { allocator.SetReadAccess(pointer, length); } accessCounter++; } }
private void SetReadAccessIfNeeded() { // accessLock protects concurrent readers from changing access permissions at the same time // while holding the pointerLock in read mode lock (accessLock) { // Only set read access if we're the first one trying to access this potentially-shared Secret accessCounter++; if (accessCounter == 1) { allocator.SetReadAccess(pointer, length); } } }