Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Easy programme up for grabs!!

Status
Not open for further replies.

0

MIS
Apr 13, 2000
7
0
0
IE
Hey everyone,<br>Ive been given this problem and can only make a very scimpy start on it....<br>can someone please help me??<br><br><br>Synchronise 2 threads: 1 prints 1, second prints 2,<br>use semiphores for synchronisation (2 needed)<br>even wait- signal<br>odd wait- signaal<br>initial value of semiphores is needed<br>prints odd one = 1, waits on semiphore, <br>even= 2, signal odd signals = 3,<br>guarantee- one thread that prints first, not necessarily the one created first; placement of semiphore is crucial.<br>if loops are incorrect, one thread may die, if 1 less digit, 2nd loop may be too small. Ensure it still gets the semiphore.<br><br>Please Please sort this out....<br>Thanks<br>ken<br><br>Ps, this has to be written in c/c++
 
I infer that U want a program that have 2 threads that go in one after the othere i.e thread 1,then 2 then 1 anfd then 2......<br>I guess I have an algo for sequencing the threads supposing we have 2 semaphores 1 and 2<br><br>main() {<br>...<br>&nbsp;p_sema(2)<br>pthread_create(func1);<br>pthread_create(func2)<br>}<br><br>func1() {<br>p_sema(1)<br>your_own_stuff()<br>v_sema(2)<br>}<br><br>func2() {<br>p_sema(2)<br>your-own_stuff2()<br>v_sema(1);<br>}<br><br>thread 1 will be the thread that alwasy starts first as we have done a P_sema(2) in the main program which creates these 2 threads.<br><br>Adios<br>amit<br><A HREF="mailto:crazy_indian@mailcity.com">crazy_indian@mailcity.com</A>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top