Click here to Skip to main content
15,916,527 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Using Dialog Box in DLL Pin
Michael P Butler15-Sep-02 9:58
Michael P Butler15-Sep-02 9:58 
GeneralRe: Using Dialog Box in DLL Pin
Mike Nordell16-Sep-02 0:24
Mike Nordell16-Sep-02 0:24 
QuestionWhere can I find the registry key for the path of the current WebBrowser / EmailReader? Pin
Ștefan-Mihai MOGA15-Sep-02 6:14
professionalȘtefan-Mihai MOGA15-Sep-02 6:14 
AnswerRe: Where can I find the registry key for the path of the current WebBrowser / EmailReader? Pin
.dan.g.15-Sep-02 15:27
professional.dan.g.15-Sep-02 15:27 
GeneralRe: Where can I find the registry key for the path of the current WebBrowser / EmailReader? Pin
Ștefan-Mihai MOGA15-Sep-02 17:58
professionalȘtefan-Mihai MOGA15-Sep-02 17:58 
GeneralRe: Where can I find the registry key for the path of the current WebBrowser / EmailReader? Pin
Mandalay16-Sep-02 3:49
Mandalay16-Sep-02 3:49 
GeneralRe: Where can I find the registry key for the path of the current WebBrowser / EmailReader? Pin
Ștefan-Mihai MOGA16-Sep-02 23:44
professionalȘtefan-Mihai MOGA16-Sep-02 23:44 
GeneralMeasure running time of Consumer - Producer Pin
tongc15-Sep-02 4:50
tongc15-Sep-02 4:50 
hi!

I'm working on a Consumer - producer program. It is required to measure the time that the producer producing, waiting and the consumer consumes and waiting. However i'm having some trouble measuring those. Does anyone have any ideas?

The following is my code that i've written so far:

<br />
//---------------------------------<br />
//  Buffer.c<br />
//---------------------------------<br />
#include "buffer.h"<br />
#include <windows.h><br />
#include "screen.h"<br />
HANDLE NFull, NEmpty;<br />
HANDLE mutexProTime, mutexConTime;<br />
int sleepTimePro = 100; //sleeping interval for sleep function of producer<br />
int sleepTimeCon = 200;//sleeping interval for sleeping function of consumer<br />
<br />
void Buffer::BufInit(void)<br />
{<br />
 bufferSize = 8; <br />
 NxtIn = 0;<br />
 NxtOut = 0;<br />
 NFull = CreateSemaphore(NULL, 0, bufferSize, 0);<br />
 NEmpty = CreateSemaphore(0, bufferSize, bufferSize, 0);<br />
 mutexProTime = CreateMutex(NULL, TRUE, 0);<br />
 mutexConTime = CreateMutex(NULL, TRUE, NULL);<br />
  proTime = proWaitTime = 0; //producing time and wait time<br />
  conTime= conWaitTime = 0;// initialise consumer consume time and consumer wait time<br />
 <br />
}<br />
void Buffer::BufPut(char c)<br />
{<br />
  <br />
  if(WaitForSingleObject(NEmpty, 10) != WAIT_OBJECT_0)<br />
   proWaitTime += 100;<br />
  <br />
  buffer[NxtIn] = c;<br />
  NxtIn = (NxtIn+1) % bufferSize;<br />
  if (NxtIn == 0)<br />
  {<br />
 scrWriteAt(0, 5, "                       ");<br />
 scrWriteAt(0, 5, "Producer is waiting");<br />
  }<br />
  else<br />
  {<br />
 scrWriteAt(0, 5, "                       ");<br />
 scrWriteAt(0, 5, "Producer is generating ");<br />
  }<br />
  ReleaseSemaphore(NFull, 1, 0);<br />
  Sleep(sleepTimePro);<br />
 <br />
  proTime += sleepTimePro;<br />
  <br />
 <br />
}<br />
char Buffer::BufGet(void)<br />
{ <br />
 char s;  <br />
 if(WaitForSingleObject(NFull, 10) != WAIT_OBJECT_0)<br />
  conWaitTime += 100;<br />
 s = buffer[NxtOut];<br />
 NxtOut = (NxtOut+1) % bufferSize;<br />
 <br />
 if (NxtOut == 0)<br />
 {<br />
  scrWriteAt(0, 7, "                              ");<br />
  scrWriteAt(0,7,"Consumer is waiting  " );<br />
 }<br />
 else<br />
 {<br />
  scrWriteAt(0, 7, "                              ");<br />
  scrWriteAt(0, 7, "Consumer is consuming  ");<br />
 }<br />
 ReleaseSemaphore(NEmpty, 1, 0);<br />
 Sleep(sleepTimeCon);<br />
 conTime += sleepTimeCon;<br />
 return s;<br />
 <br />
}<br />
long Buffer::TimeProducerProduces()<br />
{<br />
 <br />
 <br />
 return proTime;<br />
}<br />
long Buffer::TimeProducerWaits()<br />
{<br />
 return proWaitTime;<br />
}<br />
long Buffer::TimeConsumerConsumes()<br />
{<br />
 return conTime;<br />
}<br />
long Buffer::TimeConsumerWaits()<br />
{<br />
 return conWaitTime;<br />
}<br />


it seems to me that the above does not work, and it always produce the same answer each run.
GeneralRe: Measure running time of Consumer - Producer Pin
valikac15-Sep-02 5:59
valikac15-Sep-02 5:59 
GeneralRe: Measure running time of Consumer - Producer Pin
Anonymous15-Sep-02 21:37
Anonymous15-Sep-02 21:37 
GeneralRe: Measure running time of Consumer - Producer Pin
Mike Nordell16-Sep-02 0:30
Mike Nordell16-Sep-02 0:30 
GeneralRe: Measure running time of Consumer - Producer Pin
valikac16-Sep-02 11:09
valikac16-Sep-02 11:09 
Generalm_ctrEditLocation.ReplaceSel Using String Resource Pin
MJ3215-Sep-02 2:15
MJ3215-Sep-02 2:15 
GeneralRe: m_ctrEditLocation.ReplaceSel Using String Resource Pin
Pavel Klocek15-Sep-02 2:22
Pavel Klocek15-Sep-02 2:22 
GeneralRe: m_ctrEditLocation.ReplaceSel Using String Resource Pin
Gary R. Wheeler15-Sep-02 2:29
Gary R. Wheeler15-Sep-02 2:29 
GeneralOutputting Text into An Edit Control Pin
MJ3215-Sep-02 1:09
MJ3215-Sep-02 1:09 
GeneralRe: Outputting Text into An Edit Control Pin
Pavel Klocek15-Sep-02 1:12
Pavel Klocek15-Sep-02 1:12 
GeneralRe: Outputting Text into An Edit Control Pin
MJ3215-Sep-02 1:39
MJ3215-Sep-02 1:39 
GeneralOpen Text File into Hexadecimal Pin
mzakarni14-Sep-02 23:08
mzakarni14-Sep-02 23:08 
GeneralRe: Open Text File into Hexadecimal Pin
l a u r e n15-Sep-02 0:58
l a u r e n15-Sep-02 0:58 
GeneralRe: Open Text File into Hexadecimal Pin
mzakarni15-Sep-02 2:39
mzakarni15-Sep-02 2:39 
GeneralLogical bug in program Pin
axa14-Sep-02 22:20
axa14-Sep-02 22:20 
GeneralRe: Logical bug in program Pin
Hans Ruck15-Sep-02 5:54
Hans Ruck15-Sep-02 5:54 
GeneralRe: Logical bug in program Pin
axa15-Sep-02 10:44
axa15-Sep-02 10:44 
QuestionCan't a message be peeked in a thread? Pin
Chen Jiadong14-Sep-02 22:04
Chen Jiadong14-Sep-02 22:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.