简体   繁体   中英

While calling SleepConditionVariableSRW() what should be the flag value to indicate that the SRW lock is in exclusive mode?

The MSDN documentation for SleepConditionVariableSRW states that -

Flags [in] -
If this parameter is CONDITION_VARIABLE_LOCKMODE_SHARED, the SRW lock is in shared mode. Otherwise, the lock is in exclusive mode.

From this I inferred that any value other than CONDITION_VARIABLE_LOCKMODE_SHARED will imply exclusive mode SRW lock. However, when I tried providing a flag value of CONDITION_VARIABLE_LOCKMODE_SHARED + 1 the function SleepConditionVariableSRW() failed after a few tries.*

I set the flags value as 0 and all the testcases involving SleepConditionVariableSRW() passed (over and over again).

Can anybody confirm if the value of this flag is supposed to be '0' only to imply exclusive mode SRW lock? I couldn't find any mention of it in the MSDN documentation.

* I tried other non-zero values too.

Formal parameters called Flags are generally implemented as bitflags. In case of SleepConditionVariableSRW , there's only a single value currently in use. The value of CONDITION_VARIABLE_LOCKMODE_SHARED is 0x1 (ie "Bit 0"). All other bits are currently unused.

To use exclusive lock mode, bit 0 has to be unset. Since there aren't any other flags currently defined, the only legal input for exclusive lock mode is 0.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM