11-28-2007
Porter,
In my application semaphores, are not created using any threading library. Semaphores (counting) are created using sema_init. Is there any system calls or functions available to get the semaphores a thread is currently having?
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
hi, is there any command where we can monitor semaphores? (1 Reply)
Discussion started by: yls177
1 Replies
2. UNIX for Dummies Questions & Answers
Hi,
I'm new to UNIX.
I need to know what's a semaphore
Do reply.
Thanks
VJ (3 Replies)
Discussion started by: vjsony
3 Replies
3. UNIX for Advanced & Expert Users
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... (8 Replies)
Discussion started by: maverix
8 Replies
4. Shell Programming and Scripting
Hi,
I am looking to use a semaphore for the first time in one of my scripts. I am just wondering if there are any simple examples or tutorials around?
I am a beginner so the simpler the better :)
Thanks
-Jaken (2 Replies)
Discussion started by: Jaken
2 Replies
5. UNIX for Dummies Questions & Answers
what is semaphore? can any body explain it in a more simple way than the manual ??
replies appreciated
Regards
raguram R (7 Replies)
Discussion started by: raguramtgr
7 Replies
6. Programming
In my server code there is a thread per client...
The server call accept() and after that start the thread.
So there is a thread for client that save in RAM the client's message, that will be send to other clients.
Now in RAM I have created a shared memory in which thread read and write(save)... (2 Replies)
Discussion started by: italian_boy
2 Replies
7. Shell Programming and Scripting
Control two exclusively shared resources(semaphore). The two resources are two files. The producer will write even numbers to one file, and odd numbers to another one. The consumer respectively reads from each file until it gets 5 even numbers and 5 odd numbers.
Can any one help me with the... (0 Replies)
Discussion started by: gokult
0 Replies
8. Programming
If I create a semaphore and then I fork a number of child processes then all the child process use that same semaphore.
Since the process address spaces are different rfom each other then how all the child process are able to access the same semaphore?
I understand that semaphore/mutex is at os... (0 Replies)
Discussion started by: rupeshkp728
0 Replies
9. Solaris
Can anyone tell me abt the Semaphore concept and what is semaphore???
is semaphore id is associated in terms as in resources like semaphore id 1 indicates cpu share unit is given and semaphore id 2 will indicate abt the memore or semaphore id 3 will tell us the i/o components (1 Reply)
Discussion started by: aarjun07
1 Replies
10. UNIX for Beginners Questions & Answers
I was asked to add this piece of code to a c program which I will execute through the shell:
for(long i = 0; i < NITER; i++)
{ sem_wait( &sema);
count++;
sem_post( &sema); }
I didn't get it, which is the critical section ? if it's "count++" how would a thread wake up in order to enter it... (1 Reply)
Discussion started by: uniran
1 Replies
SEMA(9) BSD Kernel Developer's Manual SEMA(9)
NAME
sema, sema_init, sema_destroy, sema_post, sema_wait, sema_timedwait, sema_trywait, sema_value -- kernel counting semaphore
SYNOPSIS
#include <sys/types.h>
#include <sys/lock.h>
#include <sys/sema.h>
void
sema_init(struct sema *sema, int value, const char *description);
void
sema_destroy(struct sema *sema);
void
sema_post(struct sema *sema);
void
sema_wait(struct sema *sema);
int
sema_timedwait(struct sema *sema, int timo);
int
sema_trywait(struct sema *sema);
int
sema_value(struct sema *sema);
DESCRIPTION
Counting semaphores provide a mechanism for synchronizing access to a pool of resources. Unlike mutexes, semaphores do not have the concept
of an owner, so they can also be useful in situations where one thread needs to acquire a resource, and another thread needs to release it.
Each semaphore has an integer value associated with it. Posting (incrementing) always succeeds, but waiting (decrementing) can only success-
fully complete if the resulting value of the semaphore is greater than or equal to zero.
Semaphores should not be used where mutexes and condition variables will suffice. Semaphores are a more complex synchronization mechanism
than mutexes and condition variables, and are not as efficient.
Semaphores are created with sema_init(), where sema is a pointer to space for a struct sema, value is the initial value of the semaphore, and
description is a pointer to a null-terminated character string that describes the semaphore. Semaphores are destroyed with sema_destroy().
A semaphore is posted (incremented) with sema_post(). A semaphore is waited on (decremented) with sema_wait(), sema_timedwait(), or
sema_trywait(). The timo argument to sema_timedwait() specifies the minimum time in ticks to wait before returning with failure.
sema_value() is used to read the current value of the semaphore.
RETURN VALUES
The sema_value() function returns the current value of the semaphore.
If decrementing the semaphore would result in its value being negative, sema_trywait() returns 0 to indicate failure. Otherwise, a non-zero
value is returned to indicate success.
The sema_timedwait() function returns 0 if waiting on the semaphore succeeded; otherwise a non-zero error code is returned.
ERRORS
The sema_timedwait() function will fail if:
[EWOULDBLOCK] Timeout expired.
SEE ALSO
condvar(9), locking(9), mtx_pool(9), mutex(9), rwlock(9), sx(9)
BSD
February 1, 2006 BSD