45 lines
1.0 KiB
C
45 lines
1.0 KiB
C
|
/*******************************************************************************
|
||
|
* File: customer.c
|
||
|
* Purpose: customer thread
|
||
|
* Course: bsy
|
||
|
* Author: M. Thaler, 2011
|
||
|
* Revision: 5/2012
|
||
|
* Version: v.fs20
|
||
|
*******************************************************************************/
|
||
|
|
||
|
#include <stdio.h>
|
||
|
#include <unistd.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <time.h>
|
||
|
|
||
|
#include <pthread.h>
|
||
|
|
||
|
#include "commonDefs.h"
|
||
|
#include "mrand.h"
|
||
|
|
||
|
//*****************************************************************************
|
||
|
|
||
|
void *customer(void* data) {
|
||
|
float ranNum;
|
||
|
int i;
|
||
|
rand_t randnum;
|
||
|
|
||
|
cData *cD = (cData *) data;
|
||
|
|
||
|
rand_seed(&randnum, 0);
|
||
|
|
||
|
// put coin and select coffee
|
||
|
for (i = 0; i < ITERATIONS; i++) {
|
||
|
ranNum = rand_float(&randnum);
|
||
|
cD->coinCount += 1;
|
||
|
if (ranNum < 0.5)
|
||
|
cD->selCount1 += 1;
|
||
|
else
|
||
|
cD->selCount2 += 1;
|
||
|
}
|
||
|
|
||
|
pthread_exit(0);
|
||
|
}
|
||
|
|
||
|
//*****************************************************************************
|