1 out of 1 rated this helpful - Rate this topic

TryAcquireSRWLockExclusive function

Applies to: desktop apps | Metro style apps

Attempts to acquire a slim reader/writer (SRW) lock in exclusive mode. If the call is successful, the calling thread takes ownership of the lock.

Syntax

BOOLEAN TryAcquireSRWLockExclusive(
  __inout  PSRWLOCK SRWLock
);

Parameters

SRWLock [in, out]

A pointer to the SRW lock.

Return value

If the lock is successfully acquired or the current thread already owns the lock, the return value is nonzero.

If another thread already owns the lock, the return value is zero.

Requirements

Minimum supported client

Windows 7

Minimum supported server

Windows Server 2008 R2

Header

WinBase.h (include Windows.h)

Library

Kernel32.lib

DLL

Kernel32.dll

See also

AcquireSRWLockExclusive
Slim Reader/Writer (SRW) Locks
TryAcquireSRWLockShared

 

 

Send comments about this topic to Microsoft

Build date: 3/7/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
What's the difference between TryAcquireSRWLockExclusive and AcquireSRWLockExclusive?
TryAcquireSRWLockExclusive returns immediately. How about AcquireSRWLockExclusive? If the lock is already owned, will it wait forever until the lock is released?
Incorrect description
The part of the sentence stating "or the current thread already owns the lock" isn't correct. (at least for Windows 7) If a lock is already owned, this function will always return zero whether a lock is owned by current thread or not. SRWLOCK testLock; ::InitializeSRWLock( &testLock ); ::AcquireSRWLockExclusive( &testLock ); if( ::TryAcquireSRWLockExclusive( &testLock ) ) { printf( "TryTryAcquireSRWLockExclusive succeeded\n\n" ); ::ReleaseSRWLockExclusive( &testLock ); } ::ReleaseSRWLockExclusive( &testLock );