Solved

sem_open and sem_getvalue

Posted on 2004-10-09
2
917 Views
Last Modified: 2008-01-09
Hi,

   I have a program that does the following:

mysem = sem_open(semname, O_CREAT, 0644, 10);
sem_getvalue(mysem, &myvalue);
printf("%i", myvalue);

Very simple:
 it creates a semaphore with value 10, gets the value, and prints it out.

The problem is:
  As you can see I set the value to 10
  However, the output for the value is 1.

Why is it telling me that the semaphore has a value of 1 when I explicitly initialized it to 10?
0
Comment
Question by:jameswalt
2 Comments
 
LVL 15

Expert Comment

by:efn
ID: 12269224
I don't see anything obviously wrong.  Try checking the return values from the calls to sem_open and sem_getvalue.  Maybe one or both failed.
0
 

Accepted Solution

by:
Mamata_gd earned 50 total points
ID: 12269366
Also check if there is object with same name semname. BTW, what is 0644???
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Concatenate two strings Last and First Name 10 60
Acrinis True image 2 92
gdb doesn't stop on breakpoint 2 95
Resolve Dependency Issues 4 79
Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question