Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6009567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:59:21+00:00 2026-05-23T01:59:21+00:00

I have never understood semaphores well enough. Every time, I venture to understand them,

  • 0

I have never understood semaphores well enough. Every time, I venture to understand them, something pops up, which I don’t understand.

Here is my question at this moment:

I read in “Operating System Concepts” that: “*A semaphore S is an integer variable that, apart from initialization, is accessed only through two standard atomic operations: wait() and signal().“*

What does atomic mean here? Does it mean that this operation will be executed at one go?

But then the book goes on to give one sample implementation of wait():

wait(S) {
while S <= 0
; // no-op
S--;
}

With a while loop in it (which depends on other process), how can this ever run at one go (i.e. without any other process executing to signal, which will break the while loop)

Please explain,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T01:59:22+00:00Added an answer on May 23, 2026 at 1:59 am

    The example code for wait is just illustrative, it’s unlikely it would be implemented in this way. Most operating systems would suspend the tread trying to acquire the semaphore if the counter is not greater than zero.

    However, technically the example can be made to work. If S was flagged as volatile then a change by any other process or thread would be seen by wait(). wait() would spin in a tight loop until the condition was satisfied and would chew up the CPU, but it would work. Note that this CPU chewing is why a OS will suspend the calling thread is the condition cannot be satisfied. You’d need to do the test and decrement atomically, and this is typically accomplished by using an OS atomic function, such as InterlockedCompareExchange on Windows.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This answer hit a nerve with me on something I have never understood with
I have a feature in visual studio which I have never really understood. I
There is something I have never understood. How can a great big PC game
I have seen transaction usage in some cases but never really understood in which
Just trying to understand that - I have never used it before. How is
I have never understood what is the ideal way to name a project, package,
One thing I have never truly understood is the concept of character encoding. The
So, I've never understood the explain of MySQL. I understand the gross concepts that
I have never understood the pattern of regular expression and after googling I haven't
I've been programming in Perl for a while, but I never have understood a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.