The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How many semaphores? Watto86 UNIX for Advanced & Expert Users 8 11-07-2007 09:32 PM
semaphores kekanap Shell Programming and Scripting 1 03-27-2007 02:56 AM
semaphores qntmteleporter High Level Programming 2 01-28-2006 04:10 PM
Semaphores with key of 0 doeboy UNIX for Advanced & Expert Users 0 10-28-2004 12:41 PM
Semaphores joseph_shibu High Level Programming 1 11-01-2001 09:01 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-02-2007
Registered User
 

Join Date: Feb 2007
Posts: 11
semaphores using up and down

been searching around on how to use an up and down function with semaphores but i can't find an example. i looked into using: "semop" but i have no idea how to use it. I have been able to declared the semaphores using semget and initializing them using semctl.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 04-03-2007
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 3,502
Up and down? Do you mean a mutex?

Sempahores can have values other than one and zero. Mutexes are "switches" - either on or off (one or zero).
Reply With Quote
  #3 (permalink)  
Old 04-03-2007
Registered User
 

Join Date: Feb 2007
Posts: 11
sorry, forgot to update this. i found out that i needed to create a stuct that would implement the function i wanted. increment the semaphore by 1 or decrease it by 1.

here is where i got the idea
http://docs.linux.cz/programming/c/u...les/semab.html
Reply With Quote
  #4 (permalink)  
Old 04-03-2007
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 3,502
void main() is a terrible idea... noticed it on your link.
Reply With Quote
  #5 (permalink)  
Old 04-03-2007
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,490
should be as

Code:
int main() {
 return <n>;
}
I noticed the semaphore resource acquired is not released using
Code:
semctl + IPC_RMID;
soemthing like,
semctl(sem_id, 0, IPC_RMID, <union>);
Reply With Quote
  #6 (permalink)  
Old 04-03-2007
Registered User
 

Join Date: Feb 2007
Posts: 11
what i did was just define a number of KEYs equal to the number of semaphores i wanted and then i created 2 struct to create the functions up and down. i didn't use a void main, just main. Why would void main be bad?


you have to release the resources??? how do you do that? aren't they released as soon as the program is done?
Reply With Quote
  #7 (permalink)  
Old 04-03-2007
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,490
Quote:
just main.
But Still,

use int main and make the code to return a value !
Reply With Quote
Google UNIX.COM
Reply

Tags
linux

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:55 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0