Click here to Skip to main content
11,920,641 members (51,936 online)
Rate this:
Please Sign up or sign in to vote.
See more: C++ C Linux
#include <semaphore.h>

sem_t semA, semB;

  sem_init(&semA, 0, 0);
  sem_init(&semB, 0, 0);
int a=0,b=0;
		printf("Run aaa  %d\n",a);
		printf("go to bb  %d\n",a);
		printf("post to bbb %d\n",b);
		printf("go to aaa   %d\n",b);
Posted 4-Jan-13 18:57pm
Sandeep Mewara 5-Jan-13 0:39am
For now, without any detail on what this code should do and your efforts, question just looks like a homework.

Have you even looked at the code? Tried anything? While loop?
Something tells me: this is not a homework, or, may be, this is a homework, but on the subject OP have no clue about, as if he missed all the lectures and classes, if any. The topic is related to thread, and here there are not threads except one. I answered, please see.
nv3 5-Jan-13 5:16am
Convert the two while-loops into separate threads and all of a sudden things start to make sense! But this is your homework :-)

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

From the very beginning, it makes no sense at all. Did you learn what semaphores are for? The are used to synchronize threads in a certain way. And where are your threads? There is nothing to discuss here.


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 415
1 phil.o 170
2 Dave Kreskowiak 155
3 KrunalRohit 134
4 F-ES Sitecore 130
0 OriginalGriff 6,778
1 KrunalRohit 4,530
2 Sergey Alexandrovich Kryukov 3,203
3 George Jonsson 2,815
4 Suvendu Shekhar Giri 2,181

Advertise | Privacy | Mobile
Web01 | 2.8.151120.1 | Last Updated 5 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100