V4
This commit is contained in:
parent
8735d45f39
commit
38443df097
2 changed files with 17 additions and 9 deletions
|
@ -1,15 +1,21 @@
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
unsigned int n = 20, b = 100, w = 5;
|
||||||
|
|
||||||
class BoundedBuffer{
|
class BoundedBuffer{
|
||||||
Semaphore full(0); //initialized to 0, Since there are 0 full slots
|
//int b;
|
||||||
Semaphore empty(b); //initialized to b, Since all the slots are empty
|
Semaphore *full = new Semaphore(0); //initialized to 0, Since there are 0 full slots
|
||||||
Semaphore mutex(0);
|
Semaphore *empty = new Semaphore(b); //initialized to b, Since all the slots are empty
|
||||||
|
Semaphore *mutex = new Semaphore(1);
|
||||||
|
|
||||||
|
|
||||||
int b;
|
|
||||||
|
|
||||||
vector<string> data;
|
vector<string> data;
|
||||||
|
|
||||||
BoundedBuffer(
|
//BoundedBuffer(
|
||||||
|
|
||||||
void set_b(int val_b){ b = val_b;}
|
void set_b(int val_b){ b = val_b;}
|
||||||
|
|
||||||
|
@ -20,5 +26,5 @@ class BoundedBuffer{
|
||||||
|
|
||||||
//can't be larger than b strings
|
//can't be larger than b strings
|
||||||
//b = user input
|
//b = user input
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
|
|
||||||
#include "reqchannel.h"
|
#include "reqchannel.h"
|
||||||
#include "semaphore.h"
|
#include "semaphore.h"
|
||||||
|
#include "BoundedBuffer.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
@ -43,6 +44,8 @@ using namespace std;
|
||||||
/* CONSTANTS */
|
/* CONSTANTS */
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
// unsigned int n = 20, b = 100, w = 5;
|
||||||
|
|
||||||
/* -- (none) -- */
|
/* -- (none) -- */
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
@ -57,7 +60,6 @@ using namespace std;
|
||||||
|
|
||||||
int main(int argc, char * argv[]) {
|
int main(int argc, char * argv[]) {
|
||||||
|
|
||||||
unsigned int n = 20, b = 100, w = 5;
|
|
||||||
int option = -1;
|
int option = -1;
|
||||||
|
|
||||||
while ((option = getopt(argc, argv, "n:b:w:")) != -1){
|
while ((option = getopt(argc, argv, "n:b:w:")) != -1){
|
||||||
|
@ -74,7 +76,7 @@ int main(int argc, char * argv[]) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cout << n << b << w << endl;
|
cout << "TEST: " << n << b << w << endl;
|
||||||
|
|
||||||
Semaphore sema(5);
|
Semaphore sema(5);
|
||||||
cout << "CLIENT STARTED:" << endl;
|
cout << "CLIENT STARTED:" << endl;
|
||||||
|
|
Reference in a new issue