next up previous
Next: Synchronization and Semaphores Up: XINU Processes and Previous: Concurrent Execution of

Shared Memory in XINU

In XINU, each process has its own copy of local variables, formal parameters, and procedure calls, but all processes share the same set of global (external) variables. Consider a simple example of two processes that need to communicate with each other through a shared integer, `n'.

#include <conf.h>

int n = 0;   /* external variable shared by all processes */

main()
{
    int produce(), consume();
    resume( create(consume, 200, 20, "cons", 0) );
    resume( create(produce, 200, 20, "prod", 0) );
}

produce()
{
    int i;

    for( i=1; i<=2000; i++ )
        n++;
};

consume()
{
    int i;
    for( i=1; i<=2000; i++ )
        printf("n is %d", n);
}

The process executing `produce' loops 2000 times, incrementing `n', we call this process the producer. The process executing `consume' also loops 2000 times; it prints the value of `n' in decimal. We call this process the consumer.


Prasun Dewan
Tue Jan 13 12:23:19 EST 2004