Click here to Skip to main content
13,052,342 members (53,914 online)
Rate this:
Please Sign up or sign in to vote.
See more:
#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 17: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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 5 Jan 2013
Copyright © CodeProject, 1999-2017
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