00001
00015
00016 #include <sys/types.h>
00017 #include <sys/ipc.h>
00018 #include <sys/msg.h>
00019 #include <stdlib.h>
00020
00021 #include "CommanHeader.h"
00022
00023
00024
00025
00026
00027
00028
00029
00030 void* ConsumerThreadEntryPoint( void* aParam )
00031 {
00032 ThreadParam* args = (ThreadParam*) aParam;
00033 int yetToConsume = args->noOfItems;
00034 int clientId = args->noOfConsumers;
00035 ProducedItem* consumeItem;
00036 int ret = 0;
00037 key_t msgQFd = -1;
00038
00039
00040 struct msgbuf* sendMsg = (struct msgbuf*)malloc(KMAXSENDMSG);
00041 sendMsg->mtype = 1;
00042
00043
00044 msgQFd = msgget(KMSGQKEY, IPC_CREAT);
00045
00046 while (yetToConsume != 0)
00047 {
00048
00049 sem_wait(&args->itemLock);
00050
00051 consumeItem = PopFromStack();
00052 if (consumeItem == NULL)
00053 {
00054
00055 sem_post(&args->itemLock);
00056 continue;
00057 }
00058 yetToConsume--;
00059
00060 sprintf(&sendMsg->mtext, " Consumer#%d Consuming Produced %s\0", clientId, consumeItem->itemName);
00061 ret = msgsnd(msgQFd, sendMsg, strlen(sendMsg->mtext)+4, 0);
00062
00063
00064 sem_post(&args->itemLock);
00065 FreeItem(consumeItem);
00066 }
00067
00068 free( sendMsg );
00069 return (int*)0;
00070 }
00071
00072
00073