08-28-2007
semaphore concept
Hi All,
I am going through the semaphore concept and have a doubt regarding the same and hope to get a resolution here.
I have a file which has a number of records.
I want to write an application (in C) which will be able to do concurrent read/write on these records.
Of what I have understood about semaphores, I know that a process can obtain a lock on the critical section of code, read/write into records, then release the lock so the other processes waiting to access the data can obtain a lock.
I am confused and tend to think that "Wouldn't this concept lead to a more serious problem?" as another process, actually wanting to read/write a different record on the same file has to wait for the lock to get released by the process which has obtained the lock. If this is the case, think of a situation where we have a large number of processes (say, more than 1000) wanting to do a read/write on same/different records. Wouldn't this concept slow down the application?
Please let me know if I have misunderstood the concept and throw some light on this...
Regards
maverix
Last edited by maverix; 08-28-2007 at 12:35 PM..
Reason: remove my name in the signature
9 More Discussions You Might Find Interesting
1. HP-UX
In my location we have Hp storage (san),from there they created luns,
so could u plz send me clear document for understanding LUN. (1 Reply)
Discussion started by: Prem
1 Replies
2. UNIX for Dummies Questions & Answers
Hi all
This is my first thread here.i confused with the concept of thread.Can anyone tell me this concept in detail.my Quation may be at primary level.
Thanx in advance for help. (1 Reply)
Discussion started by: vishwasrao
1 Replies
3. UNIX for Dummies Questions & Answers
Hi all,
I am new here ,i want to know about interrupts in detail.What r
Interrupts .how they r handeled.
Thanx in adavnce. (1 Reply)
Discussion started by: vishwasrao
1 Replies
4. Shell Programming and Scripting
Hi all, I used array a lot in C,VB,C# and java but now i am very new to shell programming,so i need a start of array in shell programming. All i want to do is read a string and put it into a character type array. For reading the string,i did this:
$ read a
now i want to put the content of a... (1 Reply)
Discussion started by: gautamshaw
1 Replies
5. AIX
hi.... Friends...
Why using mirroring ?
what is the use of mirroring? just any one tell about clearly....
thanks.... (4 Replies)
Discussion started by: Kannan841
4 Replies
6. UNIX for Dummies Questions & Answers
i couldn't get what does the metainit command represents in numeric values.
(i.e)
#metainit d66 2 1 c0t0d0s4 1 c0t0d0s5
??here 2 1 1 represnts what ??
can some one tell clearly about this... (6 Replies)
Discussion started by: sriniv666
6 Replies
7. UNIX for Advanced & Expert Users
Hi Gurus,
Please help me in below requirement.
Instance =5 (it is user parameter)
total=52 (it is user parameter
i need to split this to 5 and reminder as 1 instances totally 6
for example i need to splitt to each
52/5=10.4
1-10
11-20
21-30
31-40
41-50 (2 Replies)
Discussion started by: ragu.selvaraj
2 Replies
8. UNIX for Dummies Questions & Answers
Hi..
Could someone explain about setfacl,getfacl in unix and its uses.
Regards,
Suresh (1 Reply)
Discussion started by: suresh sunkara
1 Replies
9. UNIX for Dummies Questions & Answers
Is wc -c and wc -m same ?
Shellscript::cat file1
hello
Shellscript::cat file1 | wc -c
6
Shellscript::cat file1 | wc -m
6
Shellscript::file file1
file1: ASCII text
Shellscript::uname -a
Linux was85host 2.6.27.45-0.1-vmi #1 SMP 2010-02-22 16:49:47 +0100 i686 i686 i386 GNU/LinuxAtleast... (5 Replies)
Discussion started by: shellscripting
5 Replies
LEARN ABOUT HPUX
pthread_rwlock_tryrdlock
pthread_rwlock_rdlock(3T) pthread_rwlock_rdlock(3T)
NAME
pthread_rwlock_rdlock(), pthread_rwlock_tryrdlock() - lock or attempt to lock a read-write lock for reading
SYNOPSIS
PARAMETERS
rwlock Pointer to the read-write lock to be locked for reading.
DESCRIPTION
The function applies a read lock to the read-write lock object referenced by rwlock. The calling thread shall acquire a read lock if a
writer does not hold the lock and there are no writers blocked on the lock. It is unspecified whether the calling thread acquires the lock
when a writer does not hold the lock and there are writers waiting for 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 blocks (that is, it does not return from the call) until it
can acquire the lock. Results are undefined if the calling thread currently owns a write lock on rwlock.
Implementations shall be allowed to favor writers over readers to avoid writer starvation.
A thread may hold multiple concurrent locks on rwlock (that is, successfully call the function n times). If so, the thread must perform the
matching unlocks (that is, it must call the function n times).
The function applies a read lock as in the function with the exception that the function fails if any thread holds a write lock on rwlock
or there are writers blocked on rwlock.
Results are undefined if any of these functions are called with an uninitialized read-write lock.
If a signal is delivered to a thread waiting for a read-write lock, upon return from the signal handler, the thread shall resume waiting
for the read-write lock as if it was not interrupted.
RETURN VALUE
Upon successful completion, and return zero. Otherwise, an error number is returned to indicate the error (the variable is not set).
ERRORS
If any of the following occur, the function returns the corresponding error number:
[EBUSY] The read-write lock rwlock could not be acquired for reading because a writer holds the lock or was blocked on it.
For each of the following conditions, if the condition is detected, the and functions return the corresponding error number:
[EINVAL] The value specified by rwlock does not refer to an initialized read-write lock.
[EDEADLK] The current thread already owns the read-write lock for writing.
[EAGAIN] The read lock could not be acquired because the maximum number of read locks for rwlock has been exceeded. This error
is not detected on HP-UX.
AUTHOR
and were developed by X/Open.
SEE ALSO
pthread_rwlock_init(3T), pthread_rwlock_destroy(3T), pthread_rwlock_trywrlock(3T), pthread_rwlock_wrlock(3T), pthread_rwlock_unlock(3T).
STANDARDS CONFORMANCE
Pthread Library pthread_rwlock_rdlock(3T)