![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Mutex in Perl | superuser84 | Shell Programming and Scripting | 6 | 11-12-2007 09:55 PM |
| what is diff b/w semaphore and mutex | amitpansuria | UNIX for Dummies Questions & Answers | 1 | 08-20-2007 10:45 PM |
| how to lock keyboard without using lock command | dianayun | UNIX for Dummies Questions & Answers | 7 | 06-21-2002 03:05 PM |
| mutex | sagar | UNIX for Dummies Questions & Answers | 2 | 02-04-2002 03:00 PM |
| Threads and Mutex | vthasan | High Level Programming | 2 | 11-02-2001 04:34 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
How to handle mutex lock?
Hi, I have two tasks 'Read' and 'Write' which reads and writes on a file "abc.txt" respectively.
Now I need to restrict the Write operation on the file while Read is going on, But can allow two Reads at a time. ie. two Reads can happen simultaneously, but Write can't happen at Read is going on. I can do this by using Mutex lock which can lock the file at the start of Read and release after completion of Read, But by doing this the second Read will also won't get access to the file. Can anybody have idea, how to handle this? Thanks in advance. Cheers |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
should the Read be allowed when a write is going on ?
|
|
#3
|
|||
|
|||
|
No, it shouldn't.
Normally we can allow this also, but needs the synchronizing mechcanism. For a moment, letus say it shouldn't. |
|
#4
|
|||
|
|||
|
I dont have much experience in this but may be you can use two locks ,
1) Read Lock. I am not sure but there is somthing as recursive lock which you can lock multiple times. It maintains a type of counter which increments everytime you lock it and decrements everytime you unlock it. If the value is say zero then read lock is unlocked and if > 0 then it is locked. 2) Write Lock so, At the start of Read the check fo the write lock, if it is not locked, read lock the file. At the start of Write check for both Read and write lock and if both are free then write lock the file and start writing. Last edited by gauravgoel; 03-20-2006 at 12:51 AM. |
|||
| Google The UNIX and Linux Forums |