Hi Guys
I have been given the following problem.

"There are two user processes, U1 and U2 that generate documents to be sent to one of two network printers, P1 and P2. Each printer has its own print queue with a limited buer size of three documents. When one of the user processes wishes to print a document they send it to one of the two printers by writing it to one of the printer queues. If one printer queue is full then the other one is selected. If both printer queues are full then the user process is suspended until a printer becomes available. For the simulation, use integers to represent documents. (A sequential number generator is to be be re-used from the previous program, as can the random number generator.) Your program should show the state of each of the four processes (active or suspended); the generated activity; and the state of both printer queues, at each iteration of the main loop. Tune the random number weightings so that the queues can be seen filling up and emptying."



This is how much I done, It seems to be working but not completely,because when the two queues are filled up, they do not empty (or dequeue), and also the it keeps printing suspended for each printer.

Code:
#include <stdio.h>
#include <stdlib.h>
#include "queue_int.h"


#define RAND_NO_SEED 128475
#define MAX_BUFF_LEN      3
#define P1_SND            0
#define P2_RLY            1


static int P1_suspended = 0;
static int P2_suspended = 0;


int simulated_activity()
{
    int r = rand()%99;
    if (r < 33)
        return P1_SND;
    else
        return P2_RLY;
}


static int item = 1;
int next_item() { return item++; }


void printint(int i) { printf("%i",i); }


int main(int argc, char **argv)
{
    queue_int *buff_12 = new_bounded_queue_int(MAX_BUFF_LEN);
    queue_int *buff_23 = new_bounded_queue_int(MAX_BUFF_LEN);
    srand(RAND_NO_SEED);
    int a;
    
    while(1) {
        sleep(2);
        
        if (P1_suspended) printf("\nP1 suspended\n");
        else              printf("\nP1 active\n");


        printf("buff_12: "); queue_int_print(buff_12,printint);


        if (P2_suspended) printf("\nP2 suspended\n");
        else              printf("\nP2 active\n");


        if (P1_suspended) printf("\nP1 suspended\n");
        else              printf("\nP1 active\n");


        printf("buff_23: "); queue_int_print(buff_23,printint);


        if (P2_suspended) printf("\nP2 suspended\n");
        else              printf("\nP2 active\n");


        a = simulated_activity();
        printf("\nUser 1 simulated activity: ");
        if (a==P1_SND) printf("P1_SND\n");
        else if (a==P2_RLY) printf("P2_RLY\n");


        switch( a ) {
        case P1_SND:
            if (queue_int_isfull(buff_12))
               P1_suspended = 1;
            else {
               P1_suspended = 0;
               queue_int_enqueue(buff_12,next_item());
            }
            break;
        case P2_RLY:
            if (queue_int_isempty(buff_12) || queue_int_isfull(buff_23))
               P2_suspended = 1;
            else {
               P2_suspended = 0;
               queue_int_enqueue(buff_23, queue_int_dequeue(buff_12));
            }
            break;
        }
    }
}

This is is the library file,
queue_int.h:

Code:
#ifndef QUEUE_int_H
#define QUEUE_int_H


typedef struct queue_int_implementation queue_int;


queue_int * new_bounded_queue_int(int max);
queue_int * new_unbounded_queue_int();
int queue_int_isempty(queue_int *q);
int queue_int_isfull(queue_int *q);
int queue_int_size(queue_int *q);
void queue_int_enqueue(queue_int *q, int x);
int queue_int_dequeue(queue_int *q);
int queue_int_front(queue_int *q);
void queue_int_print(queue_int *q, void (* item_print)(int item));
void queue_int_release(queue_int *q);


#endif
Any help is very appreciated!!