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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:32:09+00:00 2026-06-15T00:32:09+00:00

My code is here: http://pastebin.com/Fi3h0E0P Here is the output 0 Should we take order

  • 0

My code is here: http://pastebin.com/Fi3h0E0P

Here is the output

0
Should we take order today (y or n): y
Enter order number: 100
More customers (y or n): n

Stop serving customers right now. Passing orders to cooker:
There are total of 1 order(s)
1
Roger, waiter. I am processing order #100

The goal is waiter must take orders and then give them to the cook. The waiter has to wait cook finishes all pizza, deliver the pizza, and then take new orders.

I asked how P-V work in my previous post here.

I don’t think it has anything to do with \n consuming? I tried all kinds of combination of wait(), but none work.

Where did I make a mistake?

The main part is here:

//Producer process
 if(pid > 0)
 {
    while(1)
    {
      printf("0");
      P(emptyShelf); // waiter as P finds no items on shelf;
      P(mutex); // has permission to use the shelf
      waiter_as_producer();
      V(mutex); // cooker now can use the shelf
      V(orderOnShelf); // cooker now can pickup orders

      wait();
      printf("2");
      P(pizzaOnShelf);
      P(mutex);
      waiter_as_consumer();
      V(mutex);
      V(emptyShelf);
      printf("3 ");
    }
 }
    if(pid == 0)
    {
     while(1)
    {
     printf("1");
     P(orderOnShelf); // make sure there is an order on shelf
     P(mutex); //permission to work
     cooker_as_consumer(); // take order and put pizza on shelf
     printf("return from cooker");
     V(mutex); //release permission
     printf("just released perm");
     V(pizzaOnShelf); // pizza is now on shelf
     printf("after");
     wait();
     printf("4");

    }
  }

So I imagine this is the execution path:
enter waiter_as_producer, then go to child process (cooker), then transfer the control back to parent, finish waiter_as_consumer, switch back to child. The two waits switch back to parent (like I said I tried all possible wait() combination…).

  • 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-06-15T00:32:11+00:00Added an answer on June 15, 2026 at 12:32 am
    • change to #define PERMS (0) (it is NOT an octal file mode mask!)
    • remove all the wait();s
    • scale size by sizeof: if((shmid=shmget(1000,sizeof (int) * BUFSIZE,IPC_CREAT | PERMS)) < 0) , and others (the size is scaled up modulo semsize/pagesize, but it is a good habit to use the right size anyway)

    fixed the problem here.

    The whole idea is: you don’t need to wait; one of the {producer,consumer} will be blocked on a P() somewhere:

    from P():

    sb.sem_flg = 0; /* blocking call */
        if (semop(sid, &sb, 1) == -1)
            perror("semop");
    

    And besides: wait(&status) needs at least an argument. (and you would probably need one of the other wait functions, such as wait3() or waitpid() )

    Extra besides:

    • I would put “volatile” before the declarations of the shared objects: volatile int *buff;
    • main() should return int, returns without a value are wrong (before c99)
    • most of the pointer operations are clumsy: order = buffer[i]; is the same as order = *(buffer+i);, but more readable.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

FULL CLASS CODE HERE: http://pastebin.com/rdjDGLJS EDIT: Latest code snippet taken from original posters comment
The tutorial is here: Simple Editor and its code is here: http://pastebin.com/x12f3DtN My full
A copy of my code is here http://pastebin.com/jcLRCrQr Everything loads fine and the CCS
full code here... http://pastebin.com/EEnm8vi3 line 378 is not inserting the sections into the current
I found this code from here: http://www.cssportal.com/form-elements/text-box.htm But the problem is you can still
I am trying to get the code found here: http://snipplr.com/view/26643/mbprogresshud-with-an-asynchronous-nsurlconnection-call/ to work in my
I download the latest source code from here: http://aspnetwebstack.codeplex.com/SourceControl/list/changesets 1) add the system.web.mvc project
Basically my problem is that i've adapted a piece of code found here http://social.msdn.microsoft.com/Forums/en-US/vemapcontroldev/thread/62e70670-f306-4bb7-8684-549979af91c1
Working example is here (this script deals with the triangle animation) http://movable.pagodabox.com/ full code
I have a CSV File here: http://www.filedropper.com/excel which looks like this http://pastebin.com/ammzv4FK . What

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.