-
January 20th, 2010, 04:47 PM
#1
Mutual exclusion strategy
Hi all
For practical purposes I can say that my program has a producer thread and a consumer thread. The producer thread writes data to a circular buffer, and the consumer thread reads data from the same buffer. The circular buffer is protected by a critical section.
I don't have control over the producer thread. In fact that's a function exported by my DLL, and all I can do is to ask the user of this library to be quick in the function, and not to block. Despite the fact that my users comply with these requests, I have all the same observed that there are times the producer thread gets the mutex repeatadly, in succession, to the point of filling the buffer. As a fix, I've written a wrapper function for EnterCriticalSection (producer thread only) and after this thread enters the CS, say N times, it Sleep(50); before trying to enter the critical section.
This works, but is there a nicer or better solution? Does using fibers worth the effort of restructuring my code? Is there a magical data storage concept without any need of synchronization?
Regards
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|