Question about read writer lock


 
Thread Tools Search this Thread
Top Forums Programming Question about read writer lock
# 1  
Old 05-25-2009
Question about read writer lock

From <<Advanced Programming in the Unix>> section 11.6, it says: Although implementations vary, readerwriter locks usually block additional readers if a lock is already held in read mode and a thread is blocked trying to acquire the lock in write mode. This prevents a constant stream of readers from starving waiting writers...
--is it wrong? because multiple threads can share read lock at same time.

Last edited by robin.zhu; 05-25-2009 at 04:18 AM..
# 2  
Old 05-25-2009
I'm not certain, but (1) it depends on the implementation, and (2) it refers to the case where the lock is held by a reader AND is waiting to be acquired by a writer. If it's held by a reader and no writer is waiting, perhaps multiple readers can acquire it without problem.
# 3  
Old 05-25-2009
Lock is required during either thread is wanting a write operation.
these may be the conditions:::::
1.)Read-Write,
2.)Write-Read,
3.)Write-Write.

You don't need a Lock in this condition
Read-Read.
# 4  
Old 05-25-2009
Thanks!
I know the answer: the above description means under the condition that a read lock has already been held by a thread, if one thread tries to acquire a read lock, another one tries to acquire a write a lock, most implementation will give higher priority to the latter thread. That's why it says "This prevents a constant stream of readers from starving waiting writers"
# 5  
Old 05-25-2009
Robin, it is slightly more complicated ....

From IEEE Std 1003.1-2008. pthread_rwlock_rdlock()

The pthread_rwlock_rdlock() function shall apply a read lock to the read-write lock referenced by rwlock. The calling thread acquires the read lock if a writer does not hold the lock and there are no writers blocked on the lock.

If the Thread Execution Scheduling option is supported, and the threads involved in the lock are executing with the scheduling policies SCHED_FIFO or SCHED_RR, the calling thread shall not acquire the lock if a writer holds the lock or if writers of higher or equal priority are blocked on the lock; otherwise, the calling thread shall acquire the lock.

If the Thread Execution Scheduling option is supported, and the threads involved in the lock are executing with the SCHED_SPORADIC scheduling policy, the calling thread shall not acquire the lock if a writer holds the lock or if writers of higher or equal priority are blocked on the lock; otherwise, the calling thread shall acquire the lock.

If the Thread Execution Scheduling option is not supported, it is implementation-defined whether the calling thread acquires the lock when a writer does not hold the lock and there are writers blocked on the lock. If a writer holds the lock, the calling thread shall not acquire the read lock. If the read lock is not acquired, the calling thread shall block until it can acquire the lock. The calling thread may deadlock if at the time the call is made it holds a write lock.
# 6  
Old 05-25-2009
Thanks for your specific explanation!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

read mail question

how do I save a email I just read to a new file? Thanks. (3 Replies)
Discussion started by: drew211
3 Replies

2. UNIX for Advanced & Expert Users

Testing privileges -lock lockfile /var/lock/subsys/..- Permission denied

Hi all, I have to test some user priviliges. The goal is to be sure that an unauthorized user can't restart some modules (ssh, mysql etc...). I'm trying to automate it with a shell script but in same cases I got the syslog broadcast message. Is there any way to simply get a return code... (3 Replies)
Discussion started by: Dedalus
3 Replies

3. Red Hat

Security Question: Lock after invalid login, Session Lock and Required Minimum Password Length

Hello all, If anyone has time, I have a few questions: How do I do the following in Linux. We are using Red Hat and Oracle Enterprise Linux, which is based on Red Hat too. 1. How to lock the account after a few (like 3) invalid password attempts? 2. How do you lock a screen after 30... (1 Reply)
Discussion started by: nstarz
1 Replies

4. IP Networking

read/write,write/write lock with smbclient fails

Hi, We have smb client running on two of the linux boxes and smb server on another linux system. During a backup operation which uses smb, read of a file was allowed while write to the same file was going on.Also simultaneous writes to the same file were allowed.Following are the settings in the... (1 Reply)
Discussion started by: swatidas11
1 Replies

5. Programming

Mutex lock question

Hi all, I have a scenario where I need to use the mutex locks. The mutex locks are working fine, but sometimes I am getting into the dead lock situation. Below is the summary of my code : MUTEX LOCK performTask(); MUTEX UNLOCK. In some cases I get into the situation where... (2 Replies)
Discussion started by: cjjoy
2 Replies

6. Programming

Will memory leak happen if free reader writer lock without...

Will memory leak happen if free reader writer lock without first calling pthread_rwlock_destroy? (0 Replies)
Discussion started by: robin.zhu
0 Replies

7. AIX

Question on CD writer & backup

Hi All, 1. I have many AIX system here but none of them has any CD writer. I want to buy external CD writer so I can move around when needed. Can some one tell me which one they have. Please let me know exact model number so it will be easy for me to order it. I tried going to IBM web site,... (4 Replies)
Discussion started by: samnyc
4 Replies

8. UNIX for Dummies Questions & Answers

How to read lock terminal values in solaris

Hi all I am using sun solaris 5.8. I wanna know where the value stored if we lock/unlock the terminal and how i can read and use it to my script. I am helpless . So plzzzzzz... (0 Replies)
Discussion started by: pankajarora_12
0 Replies

9. AIX

pthread lock question

Is it possible that the function "pthread_cond_broadcast" block itself and the function "pthread_cond_wait" unblock in multi-threads programming ? The operating system is AIX 5.2, its maintenance level is : 5.2.0.4, VisualAge C++ 6.0. Thanks (0 Replies)
Discussion started by: Frank2004
0 Replies

10. UNIX for Dummies Questions & Answers

how to lock keyboard without using lock command

how can I lock my keyboard while I'm away from the computer without using lock command. What other commands gives me the option to lock keyboard device? thanks (7 Replies)
Discussion started by: dianayun
7 Replies
Login or Register to Ask a Question