operating system

Two processes communicating using (memory locations “variables” or files).

  1. 👍 0
  2. 👎 0
  3. 👁 103
  1. here is my code but have an error !!
    there are different classes.

    // this class creates the variables we are going to use in the threads
    public class Qs {

    int n; //creating an integer value
    boolean valueSet = false; //creating a boolean statement

    //creating a method with a constraint that gets or return the integer value of the number of queues
    synchronized int get() {
    if(!valueSet)// if the value was not a false value , the process will wait in the queue
    try {
    wait();
    } catch(InterruptedException e) {
    System.out.println("exception handeled");
    }
    System.out.println("Got: " + n);
    //if the value was false, it will specify the number of queues ahead and will notify the system
    valueSet = false;
    notify();
    return n;
    }


    //this method doesn't return any value, it automatically either notifies or asks the process to wait in the queue
    synchronized void put(int n) {
    if(valueSet)
    try {
    wait();
    } catch(InterruptedException e) {
    System.out.println("exception handeled");
    }
    this.n = n;
    valueSet = true;
    System.out.println("Put: " + n);
    notify();
    }
    }

    public class P

    implements Runnable { // creating an interface for the previous class
    Qs q;
    P(Qs q)

    {
    this.q = q;
    new Thread(this, "Producer").start();
    }
    // running the first thread, this thread allows the process to wait in the queue
    public void run() {
    int i = 0;
    while(true) {
    q.put(i++);
    }
    }
    }

    public class C implements Runnable {
    Qs q;
    C(Qs q) { // creating an interface for the previous class
    this.q = q;
    new Thread(this, "Consumer").start();
    }

    // running the second thread, this thread allows the process to get the integer value and be in the waiting queue
    public void run() {
    while(true) {
    q.get();
    }
    }
    }

    // this is the class which we use to test the output
    public class tester {
    public static void main(String args[]) {
    Qs q = new Qs(); //creating an object
    new P(q);
    new C(q);
    System.out.println("Press Control-C to stop.");
    }
    }

    1. 👍 0
    2. 👎 0
  2. You might try some of the following tutorials:

    http://search.yahoo.com/search?fr=mcafee&p=operating+system+tutorials

    Sra

    1. 👍 0
    2. 👎 0
  3. What do you expect for output?

    It ran and gave only "put" and "got", and does not stop on control-C.

    1. 👍 0
    2. 👎 0

Respond to this Question

First Name

Your Response

Similar Questions

  1. Math (Stats)

    In order to predict y-values using the equation of a regression line, what must be true about the correlation coefficient of the variables? A. The correlation between variables must be an x-value of a point on the graph. B. The

    asked by Ray on March 11, 2017
  2. intro to computer

    Search: Your boss is very skeptical about the idea of storing his files up in the cloud rather than on a local storage drive. He asks you to give him the various advantages of cloud storage. Which of the selections below would not

    asked by sue on June 12, 2014
  3. Child development

    Compared to adults, when children perform complex tasks they a.use less working memory. b.are likely to perform fewer processes automatically. c.are unlikely to exceed the capacity of their working memory. d.use more sensory

    asked by Woody on October 9, 2015
  4. englissh

    16-20: Read the passage and answer the questions that follow on the basis of the information provided in the passage. Dynamic Link Libraries Windows provides several files called dynamic link libraries (DILLS) that contain

    asked by avinash on August 28, 2011
  1. psychology

    Tell me how to put it together!" Kent demanded. "I can't." Alvin complained. "I know how to do it, but I can't just tell you or write it down. It just all comes together one step after another. "Alvin is attempting to explain: a.

    asked by vedrana on November 16, 2011
  2. Psychology

    This is a homework assignment for my Psychology course on Memory and learning. Find a Movie/video clip (1-3 mins)that demonstrate a concept / phenomenom relevant to learning and memory? My prof used Matrix (what we see is just our

    asked by Erica on March 12, 2009
  3. Computers

    Assume you have a computer that contains 1 GB of memory. It contains four memory slots. Each slot can contain 128 MB, 256 MB, 512MB, 1 GB, or 2GB memory modules. Two of the slots contain 512 MB memory modules. What memory chips

    asked by Jolie on January 30, 2012
  4. psychology

    Mike waits until the night before his big exam to start studying. He maintains that last minute cramming keeps the information fresh in his memory. What does connectionist network research tell us about the effectiveness of

    asked by Sarah on April 4, 2012
  1. Chemistry

    Compare and contrast the processes of nuclear fission and fusion, showing similarities and differences. Describe which, if any, of these processes is naturally occurring. If so, where?

    asked by Joanna on May 24, 2013
  2. psychology

    Contrary to what one might expect, all intellectual facets of an individual do not necessarily decrease with aging. With regard to memory, wisdom, and creativity, research has found that A. Memory processes become less efficient,

    asked by staci on May 29, 2010
  3. psychology

    Contrary to what one might expect, all intellectual facets of an individual do not necessarily decrease with aging. With regard to memory, wisdom, and creativity, research has found that A. Memory processes become less efficient,

    asked by staci on May 29, 2010
  4. Statistics

    I neep help on two questions! A condition that occurs in multiple regression analysis if the independent variables are themselves correlated is known as: 1. autocorrelation 2. stepwise regression 3. multicorrelation 4.

    asked by Debra on September 14, 2008

You can view more similar questions or ask a new question.