LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   errors when using semaphore (https://www.linuxquestions.org/questions/programming-9/errors-when-using-semaphore-620049/)

km603 02-10-2008 12:16 AM

errors when using semaphore
 
hi guys.

I don't get how to use semaphore in linux.

I am using ubuntu.

first of all, i have the following codes:

Code:

#include <semaphore.h>

sem_t sem;
int ret;
int count = 4;

/* to be shared among processes */
ret = sem_init(&sem, 1, count);

however when i complied the codes above, I got the following errors:
Code:

warning: data definition has no type or storage class
error: initializer element is not constant

what is wrong?

And another question, why can't I just use : semaphore mutex to declare?
like, semaphore mutex = 1;

thanks in advance.

tronayne 02-11-2008 08:03 AM

Take a look at the example program in the sem_wait manual page.


All times are GMT -5. The time now is 08:41 AM.