How to make Windows slim read writer lock fair?

I found out that Windows implements a thin read / write lock (see https://msdn.microsoft.com/en-us/library/windows/desktop/aa904937%28v=vs.85%29.aspx ). Unfortunately (for me) this rw-lock is neither purple nor honest (in a way). Is it possible to make rw-lock windows with some workaround or fifo? If not, in which scenarios do you use thin rw-lock windows?

0
source share
2 answers

It is unlikely that you can change the thin lock to be fair, especially since the documentation does not indicate any method of doing this, and most locks today are unfair for performance reasons.

However, it’s quite simple to collapse your own FIFO lock with Windows events and a 64-bit control word that you manipulate with compare and exchange , which is still very subtle. Here's the diagram:

, ( ) ( "" ). reset , ( slim).

:

  • - , . (2) (3).

  • N . N . , 1 - 30 , . (, ). , , (1), ( (2) → (1)).

  • (2) + + 0 . 1 , , , . manual < reset, , , FIFO. , , . , , . . ( 0), , .

  • . , . , , . , - (3) , . , , , , .

. , lock() unlock() , , , ( ), . , (, , ). , " ..." . , , , CAS.

"" - . , , . , () , 0 (), , 0 , , () , / : . , " " , , rwlock, , / . , , . rwlock: , ( /), !

, , Windows Event, - , , , . CRITICAL_SECTION.

, , FIFO. , , , , , . .

FIFO FIFO . FIFO , FIFO , FIFO: , , , "", , . : , , , , FIFO, .

- , . , . , , , , , - (, ).

, , , - . , , .

gotchas ( , , , ), . ​​ , rwlock, rwlock, . , , , , , .

- , Windows, , , , . , , , slim lock , . , -: , . , . ( ).

+1

rw-lock fifo,

, - , "" "", , . , , , , , , MS .

, , , , ; . , , ; , , .

+1

Source: https://habr.com/ru/post/1725025/


All Articles