C++ program to implement the producer-consume

November 28, 2010 at 19:57:09
Specs: Windows XP
Write a program in C++ and Win32 API to implement the producer-consumer problem.The bounded buffer pool should be implemented using an array (of type integer) containing 10 entries (i.e. 0..9), each represents a buffer used to hold an integer. To make locating a buffer in the pool easier, the array is logically implemented as a circular array using the % function in C++ to locate a buffer. You are only allowed to use two pointers (e.g. “in” for the producer thread and “out” for the consumer thread; see below) and semaphores “empty”, “full”, and “mutex” for the assignment; counters used to keep track of the number of full/empty buffers are absolutely prohibited.

Your program should create two threads for the assignment. The producer thread should ask the user to enter an integer, find an empty buffer in the pool (using “in” to locate the position of the buffer), and load it into the buffer. The consumer thread should obtain a full buffer (using “out” to locate the position of the buffer) and consume it (by printing the buffer position and its content to the screen; see below). The two threads are synchronized using the semaphores shown above.

After the producer thread has loaded an integer into an empty buffer, it should print the position of the buffer (i.e. array index) and its content to the screen. After the consumer thread has retrieved a full buffer, it should print the position of the buffer and its content to the screen. Note that the consumer thread should be delayed by 3 seconds (using Sleep(3000)) to recognize the synchronization effect more clearly.
the following is my coding but i keep getting the followint error message:
Unable to start program (file name). The system cannot find the file specified.

Here is what I did so for:
#include <windows>
#include <iostream>

HANDLE echoHandle;

int const limit = 10;
int temp_array[limit];
int counter = 0;


int num;
bool finished = false;

cout << "the thread has been created....." << endl;

while (!finished) {
cout << "enter a number: ";
cin >> num;
if (num != 99) {
temp_array[counter] = num;
cout << "number enterd = " << temp_array[counter] << endl;
finished = true;

cout << "the thread has been killed....." << endl;

return 0;

void main ()

DWORD targetThreadID;
cout << "about to create the thread....." << endl;
echoHandle = CreateThread(0,0,echo,0,0,&targetThreadID);

See More: C++ program to implement the producer-consume

Report •

November 29, 2010 at 08:21:27
Assume if the program (source code) I have typed contains errors and I pressed Run or Start Debugging button, the compiler will display this error “There were build errors. Would you like to continue and run the last successful build?” So, if I press “Yes”, this will be displayed “Unable to start program The system cannot find the file specified.”. Why these errors were displayed? Because my program (source code) contained errors, my Compiler and Linker could not create EXE file which I’m telling system to run. So, the file does not exit and system displays this error “Unable to start program, The system cannot find the file specified”. Hope it will solve your problem. If you need more help, you can PM me. I apologize for grammar and spellings.


Report •
Related Solutions

Ask Question