LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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
  Search this Thread
Old 10-03-2004, 09:34 PM   #1
feetyouwell
Member
 
Registered: Dec 2003
Location: NC, US
Distribution: Novell Linux Eval (2.6.5)
Posts: 240

Rep: Reputation: 30
questions on semaphores


Can anyone explains or reference me to some webpage that explains what exactly a semaphore is? thanks
 
Old 10-03-2004, 09:45 PM   #2
leonscape
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Debian SID / KDE 3.5
Posts: 2,313

Rep: Reputation: 48
When in doubt google is your friend.
 
Old 10-03-2004, 09:45 PM   #3
aluser
Member
 
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

Rep: Reputation: 43
The most usual use of a semaphore is actually as a mutex. It goes like this:

The purpose of a mutex is to act as a lock, so two processes or threads can't hold the lock at the same time, ever. The mutex has a counter, initialized to 1. When a process/thread wants to acquire the lock, it decrements the counter. To release it, it increments the counter. **but**, if it tries to acquire the lock and the counter is already at 0, it goes to sleep until whoever had the lock releases it, then decrements the counter and goes about its business.

So with a mutex, the counter is always 1 or 0.

A semaphore can be initialized to values higher than 1, say n. In this case, only up to n processes/threads can hold the semaphore at one time. There aren't a ton of situations where this is useful.
 
Old 10-03-2004, 09:55 PM   #4
feetyouwell
Member
 
Registered: Dec 2003
Location: NC, US
Distribution: Novell Linux Eval (2.6.5)
Posts: 240

Original Poster
Rep: Reputation: 30
yes leonscape, in deed I went on google before I entered here, however, sometimes people's explaination can be better and easier to understand than the technical papers on various websites in google's results page. And thanks, aluser, your answer is very helpful.
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
semaphores and threads aenasir Programming 0 10-06-2004 09:07 PM
What are lightweight semaphores ? indian Programming 6 10-02-2004 07:48 AM
What is Semaphores? imsajjadali Red Hat 3 04-23-2004 01:26 AM
Semaphores help mojozoox Programming 1 01-07-2004 08:41 AM
semaphores charles_sjc Linux - Software 2 12-06-2003 12:15 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:31 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration