Search code examples
clinuxmultithreadingpthreadsrwlock

Pthread: How exactly work rwlockattr


I've got a question about "rwlocks", especial about "rwlockattr".

I've got a linked list with several threads working with. Every Member on this list has got a "rwlock". So now I want to set up a rule to secure that threads who want access a write-lock have a higher priority. My intention is to use

int pthread_rwlockattr_setkind_np(pthread_rwlockattr_t *attr,int pref);

So now my Question; Do I need to initialize a "rwlockattr" for every "rwlock" in my linked List or is it enough to set up a global "rwlockattr", initialize it and set up the "PTHREAD_RWLOCK_PREFER_WRITER_NP" rule ?

regards


Solution

  • With every rwlock there is some by default attributes associated with it. For the pthread_rwlock_init() go through this link which will give you more information that how to use rwlock.

    You can assign single attribute to your rwlocks. You globally create a single attribute and assign to your rwlocks having the same nature.

    Go through this to understand the use of pthread_rwlock.

    In general Attributes are to decide the nature of your rwlock.