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) client's message :
server.c
Code:
Now I must synchronized the threads by semaphore to read and write into shared memory.Like this : all thread can read, but when a thread write other thread can't do anything , only WAIT that the writing thread signals it has finished. I don't know how can I do... Can someone help me with some example? how can I manage a semaphore??
Thank you very much!
Last edited by pludi; 03-25-2010 at 07:57 AM..
Reason: code tags, please...
I'm running one multithreaded application, in that one of my thread
is waiting infinitely in a semphore. Is there a way to determine, in
which semaphore the particular thread is waiting and which thread(s)
is holding the semaphore. (5 Replies)
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)
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)
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)
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)
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)
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)