Producer-Consumer problem

I am trying to get this to run, but I am having a problem with it telling me I have an undefined reference to _imp_pthread_create and _imp_pthread_exit at multiple locations. Starting with line 122. I can't figure it out.

To add a library to the project in CodeBlocks right click on your project in the Management window and select Build Options. At this point you should be on the Compiler Flags tab. This would be a good time to increase your compiler error levels. After you select all the C++ specific warnings you will need to select the linker settings tab and then select Add under the Link Libraries window. Then add the pthread library, you will probably want to search for it using the ... icon.

Thank you! I got that running but now I am having multiple problems. This is what I need:

The statistics to be maintained are:Store-wide total sales
Month-wise total sales (in all stores)
Aggregate sales (all sales together)
Total time for simulation (from begin to end)
Each producer produces records randomly. Assume that the DD field is 1-30, MM is 01-
12, and YY is always 06. Store IDs are in the 1 to p range (where p is the number of
producers). The register numbers range from 1-10 for any store. The sale amount in each
item can range between 0.50 and 999.99. Each producer generates its record with random
data. Run the program until 10,000 items are produced by all producers together.
Obviously, the number of items produced so far (by all producers) need to be maintained
in shared memory. Each producer is assigned a fixed store ID when it is created. It has
the following structure:

Your "semaphores" are completely broken. You need to use the synchronization primitives provided by the threading library - pthreads in this case.
Use a pthread_mutex_t as a generic lock for mutually exclusive access.
Use a pthread_cond_t to block one or more threads on a predicate condition.