Skip to main content

Thread: Semaphore for N process


hi

i'm not sure whether right subforum here problem:

i'm trying understand semaphores
have task have n proceses , have ensure executed 1 after another

p1 > p2 > p3 > .. > pn

think done 1 semaphore , variable store process number executed, , when process p1 stop increment variable 2 , process p2 can start. i'm not quite sure how can it, nor understant whole semaphore concepth.

here soul explain my?

many

to simple, semaphore "structure" synchronize processes in multi-process environment. semaphores have internal positive integer value , processes can interact semaphore using only 2 functions acquire , release execute atomically. behavior follows:

acquire: wait until value greater 0, when is, decrease 1 , continue execution.

release: increase value of semaphore 1.

trying make barriers using semaphores. can done using 1 semaphore , value wouldn't practical.

recommend using "split binary semaphore"(a group of semaphores sum of value 0 or 1) having n semaphores, 1 each process. starting 0 except p1's semaphore starts one.

idea each process waits til semaphore gives him green light, needs done , gives green light next:

code:
process i:    acquire(sem[i]);  //do work  release(sem[i+1]);
hope helps ya,
bye bye


Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk [SOLVED] Semaphore for N process


Ubuntu

Comments

Popular posts from this blog

Falang and too many redirects - Joomla! Forum - community, help and support

Infinite loop detected in JErrorInfinite loop detected in JError - Joomla! Forum - community, help and support

logged out from joomla! - Joomla! Forum - community, help and support