Srwlock allows us to distinguish the threads (the reader thread) that want to read the value of the resource from the threads (The writer thread) that want to update the value of the resource ).
It is feasible to allow all reader threads to access Shared resources at the same time, because there is no risk of data destruction.
Synchronization is required only when the writer wants to update the resource. In this case, the writer thread should exclusively access the resource:
No other threads, whether reading or writing, are allowed to access resources.
Initialization
Void initializesrwlock (psrwlock srwlock );
The writer thread can call acquiresrwlockexclusive to obtain exclusive access to protected resources.
After the resource is updated, call releasesrwlockexclusive to lock the resource.
The reader thread has two operations:
Void acquiresrwlockshared (psrwlock srwlock );
Void releasesrwlockshared (psrwlock srwlock );
Unsupported: srwlock cannot be obtained recursively. A thread cannot lock the resource multiple times to write the resource multiple times and then release it multiple times.