PDA

View Full Version : errors when using semaphore


shadow_boi
February 9th, 2008, 05:39 PM
hi guys.

I am using ubuntu.

My codes have these lines:

semaphore mutex = 1;
semaphore full = 0;
semaphore empty = 9;

when I compiled my codes in terminal, i got the following errors:

error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘mutex’
error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘full’
error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘empty’

Can you tell me what i did wrong?

thanks.

hod139
February 9th, 2008, 05:44 PM
What is a semaphore? Is it a class that you wrote? The compiler has no idea what it is.

shadow_boi
February 9th, 2008, 06:00 PM
ph.

i thought it is a class in the c library.

ok, now i got it.

thanks.

shadow_boi
February 9th, 2008, 06:15 PM
however, even i do:

#include <pthread.h>
pthread_semaphore_t *headmutex;

I also got errors.

aks44
February 9th, 2008, 06:27 PM
Google only yields TWO (!!!) results when searching for pthread_semaphore_t. That makes me seriously doubt that it is declared in pthread.h (or anywhere else for that matter).........


EDIT: here's what the first Google link (http://www.cs.ucsb.edu/~rich/class/cs170/notes/Semaphores/index.html) says about it:
/* NOTE: this code is notional only; the Pthreads package does not include
* support for semaphores. They are imagined here for purposes of
* presentation only. This code would never compile, let alone run.
*/(it is even written in bold in the original page, just above the code you copy-pasted from that very page)

:roll:

shadow_boi
February 9th, 2008, 06:36 PM
hm.

thanks.

so i need to write my own semaphone class, since either c library or ubuntu has it?

aks44
February 9th, 2008, 06:39 PM
http://www.google.com/search?q=posix+semaphore