-
January 21st, 2010, 06:27 PM
#16
Re: Mutual exclusion strategy
1a) Sleep polling on the producer side is not a good idea. Use event polling if anything - but even that won't guarantee that the thread will make progress if there are multiple producers.
1b) The event doesn't have to be exposed to the user. PRODUCER_FN could deal with it internally. The easy solution is to event-wait within PRODUCER_FN. The API is already a blocking API (due to "EnterCS"), so you're not changing much.
Choosing between the two is a design decision only you can make. You could even combine the two by having both a blocking "produce()" and non-blocking "try_produce(timeout)" (if true non-blocking is required).
2) The only thing you should care about is defining the requirements and semantics of your library interface - and meeting those requirements of course. Then the users of your library can make proper design decisions based on a well-defined API.
For producer/consumer queue's in general:
- Never sleep() poll
- Never sleep() (never necessary in a properly designed multi-threaded app)
- Only event-poll if you absolutely have to
- Always prefer event-waiting over event-polling
- The API must deal with overflow, because it can and will happen.
gg
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
|