So I'm seeing a simple productive / consumer queue in C ++ I use to promote threading I will end the tax but this example is just using pthreads. I will also end up using a lot of OO approach, but I think that at this time I can blur the details that are interested in it.
Even though the specific issues I am concerned about
- Since this code is using push_back and pop_fruit of the stud :: deck - it may be in separate threads Allocation and delineation of the underlying data - I believe this is bad (undefined behavior) - what is the easiest way to avoid it?
- Nothing is unstable but important bits are protected by mutes what do I need to mark anything as unstable and if so what? - I do not think I will do this because I believe Mute X contains appropriate memory barriers, but I have uncertainty.
Is there any other worrisome issues?
Anyway heres the code:
#include Edit:
I ended up removing this implementation, I now use a modified version of this code My revised edition of Anthony Williams's can be found This revised version uses a more sensible position variable-based approach.
-
This is fully valid for allocating memory in one thread and both Threads are in the same process, so it's free in another.
-
Using a mute to provide access to the deck should provide the correct memory access configuration. Edit
Edit: The second thing to think about the nature of the manufacturer and the consumer is that in your synthetic example there are some subtleties associated with actual implementation. . For example, if you synchronize the manufacturer with the consumer, are not they operating at the same rate? You may consider using something like a pipe or OS queue instead of a deck so that the user can block the reading, if no data is ready for the process.
Comments
Post a Comment