Fixed compilation errors.

This commit is contained in:
shadow8t4 2015-11-06 12:48:11 -06:00
parent 2b113344a3
commit b2e95401be
3 changed files with 15 additions and 7 deletions

View file

@ -1,5 +1,7 @@
#include "semaphore.h"
#include "BoundedBuffer.h" #include "BoundedBuffer.h"
//#include "semaphore.h"
//#include <stdio> //#include <stdio>
#include <string> #include <string>
#include <vector> #include <vector>
@ -14,10 +16,10 @@ void BoundedBuffer::push(string item){
empty.P(); empty->P();
data.push_back(item); data.push_back(item);
full.V();//increment the number of full slots now. full->V();//increment the number of full slots now.
} }
void BoundedBuffer::pop(){ void BoundedBuffer::pop(){

View file

@ -1,15 +1,19 @@
#ifndef _BoundedBuffer_H_
#define _BoundedBuffer_H_
#include <vector> #include <vector>
#include <string> #include <string>
#include <semaphore.h> //#include <semaphore.h>
using namespace std; using namespace std;
unsigned int n = 20, b = 100, w = 5; extern unsigned int n, b, w;
class BoundedBuffer{ class BoundedBuffer{
//int b; //int b;
Semaphore full(); //initialized to 0, Since there are 0 full slots Semaphore *full = new Semaphore(0); //initialized to 0, Since there are 0 full slots
Semaphore *empty = new Semaphore(b); //initialized to b, Since all the slots are empty Semaphore *empty = new Semaphore(b); //initialized to b, Since all the slots are empty
Semaphore *mutex = new Semaphore(1); Semaphore *mutex = new Semaphore(1);
@ -29,3 +33,4 @@ class BoundedBuffer{
//b = user input //b = user input
}; };
#endif

View file

@ -44,8 +44,6 @@ using namespace std;
/* CONSTANTS */ /* CONSTANTS */
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
// unsigned int n = 20, b = 100, w = 5;
/* -- (none) -- */ /* -- (none) -- */
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
@ -62,6 +60,9 @@ int main(int argc, char * argv[]) {
int option = -1; int option = -1;
unsigned int n;
unsigned int b;
unsigned int w;
while ((option = getopt(argc, argv, "n:b:w:")) != -1){ while ((option = getopt(argc, argv, "n:b:w:")) != -1){
switch (option){ switch (option){
case 'n' : case 'n' :