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 7692159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:47:20+00:00 2026-05-31T20:47:20+00:00

I am doing self-studying of operating systems. Tanenbaum in his book modern operating systems

  • 0

I am doing self-studying of operating systems. Tanenbaum in his book modern operating systems states an example where he explains how three semaphores (one of which is a mutex) coordinate a producer-comsumer process pair. I am having little trouble grasping it. Can anyone please explain how it is being achieved. Any help will be appreciated. Thanks.

    #define N 1 00
    typedef int semaphore;
    semaphore mutex = 1 ;
    semaphore empty = N;
    semaphore full = 0;
    void producer(void)
    {

    int item;
    while (TRUE) {
    item = produce_item( );
    down( &empty);
    down( &mutex);
    inserUtem(item);
    up(&mutex);
    up(&full);
}

    void consumer(void)
    {

    int item;
    while (TRUE) {
    down(&full);
    down( &mutex);
    item = remove_ item( );
    up(&mutex);
    up(&empty);
    consume_item(item);

}
  • 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-31T20:47:21+00:00Added an answer on May 31, 2026 at 8:47 pm

    The (mutex) semahore is initialized to 1. Only one thread can get this one unit, all others are blocked. It’s only purpose is to prevent more than one thread, of any type, accessing the queue & so ensuring that a typical queue implementation is thread-safe.

    One semaphore, (full), is initialized to zero and counts the number of items in the queue.

    One semaphore (empty), is initialized to the queue length and counts the number of free spaces in the queue.

    That’s it really. To shove an object on, first wait on (empty) to ensure that there is a free space, then wait on (mutex) to get access to the queue, push on the object, (yes, there will always be a space available – no need to check the queue count), signal (mutex) to unlock the queue, and finally signal (full) so that any consumer thread that is waiting, or will later turn up, can get a unit that represents an object in the queue.

    To pop an object off, first wait on (full) to ensure that an object is available on the queue, then wait on (mutex) to get access to the queue, pop off the object, (yes, there will always be an object on the queue – no need to check the queue count), signal (mutex) to unlock the queue, and finally signal (empty) so that any producer thread that is waiting, or will later turn up, can get a unit that represents a free space in the queue.

    This is Computer Science 101 stuff – an absolutely classic producer-consumer blocking queue.

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

Sidebar

Related Questions

I'm studying for a M$ certificate. I use the 'self-paced' Training Kit (book). I
I doing a rails project where I'm using a self joining one-to-many setup. I
I find my self doing this type of IF statement allot. For example: if($variable
I have very little experience with ASP.NET and I am doing some self-training before
I am doing this with the following: [[self navigationController] setNavigationBarHidden:YES animated:YES]; and also I
After doing some Core animations using: [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:0.5]; [self setAffineTransform:CGAffineTransformIdentity]; [UIView
I'm doing the following and always get green pins: pin.pinColor = MKPinAnnotationColorRed; [self.mapView addAnnotation:pin];
I'm currently self-studying C for mastering an university project. In that project we have
I was doing some self-learning on how to pass data from JQuery Ajax to
When I was doing some self-learning on JQuery Ajax in Cakephp, I found out

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.