This commit is contained in:
Eric Buxkemper 2015-11-06 12:53:10 -06:00
parent 38443df097
commit 9e67f43b8e
3 changed files with 29 additions and 19 deletions

View file

@ -1,13 +1,5 @@
void BoundedBuffer::push(string item){ void BoundedBuffer::push(string item){
/* if(there is some empty slot){//data.size < b
data.push_back(item);
}else{
wait();
}
*/ //replace with
empty.P(); empty.P();
data.push_back(item); data.push_back(item);
@ -16,6 +8,8 @@ void BoundedBuffer::push(string item){
} }
void BoundedBuffer::pop(){ void BoundedBuffer::pop(){
full.P();
data.pop(item);
empty.V();
} }

View file

@ -6,13 +6,11 @@ using namespace std;
unsigned int n = 20, b = 100, w = 5; unsigned int n = 20, b = 100, w = 5;
class BoundedBuffer{ class BoundedBuffer{
//int b;
Semaphore *full = new Semaphore(0); //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);
vector<string> data; vector<string> data;
//BoundedBuffer( //BoundedBuffer(

View file

@ -78,6 +78,7 @@ int main(int argc, char * argv[]) {
cout << "TEST: " << n << b << w << endl; cout << "TEST: " << n << b << w << endl;
BoundedBuffer buff();
Semaphore sema(5); Semaphore sema(5);
cout << "CLIENT STARTED:" << endl; cout << "CLIENT STARTED:" << endl;
@ -85,11 +86,12 @@ int main(int argc, char * argv[]) {
if(pid == 0){ if(pid == 0){
cout << "Establishing control channel... " << flush; cout << "Establishing control channel... " << flush;
RequestChannel chan("control", RequestChannel::CLIENT_SIDE); control chan("control", RequestChannel::CLIENT_SIDE);
cout << "done." << endl; cout << "done." << endl;
/* -- Start sending a sequence of requests */ /* -- Start sending a sequence of requests */
/*
string reply1 = chan.send_request("hello"); string reply1 = chan.send_request("hello");
cout << "Reply to request 'hello' is '" << reply1 << "'" << endl; cout << "Reply to request 'hello' is '" << reply1 << "'" << endl;
@ -111,6 +113,8 @@ int main(int argc, char * argv[]) {
string reply4 = chan.send_request("quit"); string reply4 = chan.send_request("quit");
cout << "Reply to request 'quit' is '" << reply4 << "'" << endl; cout << "Reply to request 'quit' is '" << reply4 << "'" << endl;
*/
}else{ }else{
execve("dataserver", argv, argv); execve("dataserver", argv, argv);
} }
@ -118,10 +122,24 @@ int main(int argc, char * argv[]) {
usleep(1000000); usleep(1000000);
} }
void Req_Thread(RequestChannel chan){
//handles the data moving between the Client and Bounded Buffer
for(int i=0; i < 3; i++){
chan.send_request("newthread");
}
}
void Worker_Thread(void* arg){
//handles the data moving between the Server and Bounded Buffer
channel_name = control.send_request("newthread");
RequestChannel * channel_ret = new RequestChannel(channel_name, CLIENT_SIDE);
while(true){
string req = BB.pull();
string resp = channel_ret -> send_request(req);
}
}
/* /*
void* Worker_Thread();
void* Req_Thread();
void* void*
*/ */