简体   繁体   中英

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

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.

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