Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 10 of 10

Thread: Question about Bounded Buffer

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Arrow Question about Bounded Buffer

    Hello

    Shared Memory Solution

    # difine BUFFER_SIZE 10 
    typedef struct{
    .....
    } item;
     
    item buffer[BUFFER_SIZE];
    int in=0;
    int out=0;


    this code for producer

    while (true) {
    /* produce an item */ 
    while (((in=(in+1)%BUFFER SIZE count)==out);
    /* do nothing --  no free buffers */
    buffer[in]= item;
    in=(in+1)%BUFFER SIZE ;
    }

    this code for consumer

    while (true){
    while (in==out)
    //do nothing -- nothing to consume 
     
    //remove an item from the buffer 
    item = buffer[out];
    out =(out+1)% BUFFER SIZE ;
    return item ;
     
    }

    this solution is correct , but can only use BUFFER_SIZE-1elements

    now i want Solution to this question

    Modify the producer , consumer code for having n element for the buffer??


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Question about Bounded Buffer

    Is this java code?

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Mar 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Question about Bounded Buffer

    yes dear that java code
    i am want Solution important

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Question about Bounded Buffer

    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Mar 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Question about Bounded Buffer

    It seems you do not understand my problem?

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Question about Bounded Buffer

    This section of the forum is for people who are having problems with their java code.
    If you want help with your java code, please post your code and ask questions about the problems you are having.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Mar 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Question about Bounded Buffer

    dear
    this code of java
    and this proplem i want producer , consumer code for having n element for the buffer

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Question about Bounded Buffer

    This is not java:
    # difine BUFFER_SIZE 10 
    typedef struct{

    i want
    You are in the wrong section then. You seem to be asking for someone to write code for you. This section is for posting java code you are having problems with.

    I've moved this thread to another section.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Mar 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Question about Bounded Buffer

    hhhhhhhhhhhhhh

    my dear this code not Official but I wrote in general
    I want the idea only to resolve the question

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Question about Bounded Buffer

    If you have questions about your code, post your code and your questions.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Question on bounded buffer
    By Newbie Java in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 24th, 2013, 09:32 AM
  2. Saving an array to a buffer.
    By Tyluur in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 13th, 2012, 12:00 AM
  3. Help with Bounded Buffer problem
    By Stockholm Syndrome in forum What's Wrong With My Code?
    Replies: 6
    Last Post: April 4th, 2012, 07:02 PM
  4. PLEASE HELP ME with double buffer
    By DouboC in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 10th, 2011, 05:32 PM
  5. The Bounded Buffer Problem
    By skatescholar in forum Java Theory & Questions
    Replies: 0
    Last Post: April 8th, 2010, 11:22 AM