DS 7 - Semaphores
 All Data Structures Files Functions Variables Macros Pages
ds7.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <semaphore.h>
#include <pthread.h>

Data Structures

struct  arg_t
 Thread specific informations for consumer and producer threads. More...

Macros

#define BUFFER_SIZE   4
 BUFFER_SIZE

Functions

void * producer_thread (void *arg)
 Producer routine.
void * consumer_thread (void *arg)
 Consumerer routine.
int main (int argc, char **args)
 Main routine.

Macro Definition Documentation

#define BUFFER_SIZE   4

BUFFER_SIZE

Size in bytes of the shared buffer

This holds the size of the circular buffer shared between producer and consumer

Function Documentation

void* consumer_thread ( void *  arg)

Consumerer routine.

This is the routine for the consumer. It consumes one byte at a time from the shared buffer.

int main ( int  argc,
char **  args 
)

Main routine.

The main will have to:

  1. Parse the parameters
  2. Initialize the semaphore
  3. Initialize the shared buffer
  4. Span producers and consumers
Parameters
argcnumber of parameters
argscommand line parameters
Returns
0 on sucess, 1 on error
void* producer_thread ( void *  arg)

Producer routine.

This is the routine for the producer. It produces one byte at a time and puts it in the shared buffer.