Note that there are some explanatory texts on larger screens.

plurals
  1. POUpgradeable read/write lock Win32
    primarykey
    data
    text
    <p>I am in search of an upgradeable read write lock for win32 with the behaviour of pthreads rwlock, where a read lock can be up- and downgraded.</p> <p>What I want:</p> <pre><code>pthread_rwlock_rdlock( &amp;lock ); ...read... if( some condition ) { pthread_rwlock_wrlock( &amp;lock ); ...write... pthread_rwlock_unlock( &amp;lock ); } ...read... pthread_rwlock_unlock( &amp;lock ); </code></pre> <p>The upgrade behaviour is not required by posix, but it works on linux on mac.</p> <p>Currently, I have a working implementation (based on an event, a semaphore and a critical section) that is upgradeable, but the upgrade may fail when readers are active. If it fails a read unlock + recheck + write lock is necessary.</p> <p>What I have:</p> <pre><code>lock.rdlock(); ...read... if( some condition ) { if( lock.tryupgrade() ) { ...write... lock.unlock(); return; } else { lock.unlock(); // &lt;- here, other threads may alter the condition -&gt; lock.wrlock(); if( some condition ) { // so, re-check required ...write... } lock.unlock(); return; } } ...read... lock.unlock(); </code></pre> <p><strong>EDIT: The bounty:</strong></p> <p>I am still in search, but want to add some restrictions: it is used intra-process-only (so based on critical sections is ok, WIN32 mutexes are not ok), and it should be pure WIN32 API (no MFC, ATL etc.). Acquiring read locks should be fast (so, acquiring the read lock should not enter a critical section in its fast path). Maybe an InterlockedIncrement based solution is possible?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload