From 9e67f43b8e24df17e256fc0403ac046cf11b2de7 Mon Sep 17 00:00:00 2001 From: Eric Buxkemper Date: Fri, 6 Nov 2015 12:53:10 -0600 Subject: [PATCH] V5 --- BoundedBuffer.cpp | 12 +++--------- BoundedBuffer.h | 4 +--- simpleclient.cpp | 32 +++++++++++++++++++++++++------- 3 files changed, 29 insertions(+), 19 deletions(-) diff --git a/BoundedBuffer.cpp b/BoundedBuffer.cpp index 0447048..a64a667 100755 --- a/BoundedBuffer.cpp +++ b/BoundedBuffer.cpp @@ -1,13 +1,5 @@ void BoundedBuffer::push(string item){ -/* if(there is some empty slot){//data.size < b - data.push_back(item); - }else{ - wait(); - } -*/ //replace with - - empty.P(); data.push_back(item); @@ -16,6 +8,8 @@ void BoundedBuffer::push(string item){ } void BoundedBuffer::pop(){ - + full.P(); + data.pop(item); + empty.V(); } \ No newline at end of file diff --git a/BoundedBuffer.h b/BoundedBuffer.h index 5d18136..5d14b02 100755 --- a/BoundedBuffer.h +++ b/BoundedBuffer.h @@ -6,13 +6,11 @@ using namespace std; unsigned int n = 20, b = 100, w = 5; class BoundedBuffer{ - //int b; + 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 *mutex = new Semaphore(1); - - vector data; //BoundedBuffer( diff --git a/simpleclient.cpp b/simpleclient.cpp index 04d9e35..428afdd 100755 --- a/simpleclient.cpp +++ b/simpleclient.cpp @@ -77,7 +77,8 @@ int main(int argc, char * argv[]) { } cout << "TEST: " << n << b << w << endl; - + + BoundedBuffer buff(); Semaphore sema(5); cout << "CLIENT STARTED:" << endl; @@ -85,11 +86,12 @@ int main(int argc, char * argv[]) { if(pid == 0){ cout << "Establishing control channel... " << flush; - RequestChannel chan("control", RequestChannel::CLIENT_SIDE); + control chan("control", RequestChannel::CLIENT_SIDE); cout << "done." << endl; /* -- Start sending a sequence of requests */ - + +/* string reply1 = chan.send_request("hello"); cout << "Reply to request 'hello' is '" << reply1 << "'" << endl; @@ -111,6 +113,8 @@ int main(int argc, char * argv[]) { string reply4 = chan.send_request("quit"); cout << "Reply to request 'quit' is '" << reply4 << "'" << endl; +*/ + }else{ execve("dataserver", argv, argv); } @@ -118,10 +122,24 @@ int main(int argc, char * argv[]) { 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* */ \ No newline at end of file