int int_pipe_write(int_pipe_t *intp, int n) { while(int_pipe_full(intp) && !int_pipe_closed(intp)) { /* Busy wait... */} if(int_pipe_closed(intp)) {return 0;} assert(!int_pipe_full(intp) && !int_pipe_closed(intp)); bounded_buffer_add(&intp->buf, n); return 1; }
static void producer(void *arg) { BufferElem elem; int i = 0; elem.id = (int) arg; while (1) { /* Place the next computed Fibonacci result into the buffer */ elem.arg = i; elem.val = fib(i); bounded_buffer_add(queue, &elem); i = (i + 1) % FIB_MODULUS; } }