multiConsumer - #include #include #include # #include...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
#include ". .\myThread.h" #include ". .\. .\myLog\myLog.h" #include ". .\. .\myException\myException.h" #include ". .\. .\mySemaphore\mySemaphore.h" # const int numOfConsumers = 5; const int MAX_LENGTH = 64; myLog winLog("consumer.txt"); m string chop(string str) { int i; for(i = 0; i < str.size(); i++) { if ( str[str.size()-1] == '\n'|| str[str.size()-1] == '\r' || str[str.size()-1] == ' ' || str[str.size()-1] == '\t') str.erase(str.begin() + str.size() -1 ); else break; } for(i = 0; i < str.size(); i++) { if ( str[0] == '\n'|| str[0] == '\r' || str[0] == ' ' || str[0] == '\t') str.erase(str.begin()); else break; } return str; } // this is the thread callback (thread procedure), represents each consumer DWORD WINAPI consumerThread(LPVOID threadInfo) { // this structure will contain all the data this callback will work on myThreadArgument* threadArgument = (myThreadArgument*)threadInfo; // the semamphore to protect the access to the system log file mySemaphore* logSemaphore = threadArgument->getLogSemaphore(); // the name of current thread string& consumerName = threadArgument->getConsumerName(); s try { // open the semaphore that is created by the producer string& producerSemaphoreName = threadArgument- >getProducerSemaphoreName(); mySemaphore producerSemaphore(producerSemaphoreName,0,0,OPEN); // the file name that the producer is writing to string& producerFileName = threadArgument->getProducerFileName(); s // the main semaphore mySemaphore* mainSemaphore = threadArgument->getMainSemaphore();
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/27/2011 for the course COMPUTER 101 taught by Professor Bobthebuilder during the Spring '11 term at Columbia College.

Page1 / 4

multiConsumer - #include #include #include # #include...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online