LinuxQuestions.org
Support LQ: Use code LQCO20 and save 20% on CrossOver Office
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 02-10-2008, 12:16 AM   #1
km603
LQ Newbie
 
Registered: Jan 2008
Posts: 4

Rep: Reputation: 0
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.
 
Old 02-11-2008, 08:03 AM   #2
tronayne
Senior Member
 
Registered: Oct 2003
Location: Michigan
Distribution: Slackware 32- & 64-bit Stable
Posts: 1,826

Rep: Reputation: 359Reputation: 359Reputation: 359Reputation: 359
Take a look at the example program in the sem_wait manual page.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Issue with semaphore implementation ketanu Programming 3 03-04-2007 08:45 AM
Semaphore vs Signal scanner Linux - General 4 11-18-2006 01:05 PM
Semaphore tzzdvd Programming 1 05-24-2005 09:23 PM
semaphore beginner_84 Programming 5 08-25-2004 06:54 PM
about semaphore dummyagain Programming 1 11-11-2003 11:09 AM


All times are GMT -5. The time now is 04:50 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration