[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 170
  • Last Modified:

Code for Q functions?

Anybody want to post code or URL to code for generic Q functions:
1)  AddQ() will signal an internal event.
2)  RemoveQ() will wait on the event or timeout.
But the trick is that it will work even under scenerio of multiple producers and/or multiple consumers on the Q (multi-thread).
0
tflai
Asked:
tflai
  • 4
1 Solution
 
tflaiAuthor Commented:
Hmm...  This may sound to some experts as yet another homework.  I'd better clear it up.
I've already have a generic Q functions written.  There is just some little confusion on RemoveQ(), in particular.  It used to be something like the following psuedo-code:
while 1 loop
  enter critical section
  remove head element from the list
  if list is empty reset the event
  leave critical section
  return the list element if it was there
  wait on the event with certain timeout
end while

0
 
Tommy HuiCommented:
One very good book I've seen on this subject is Win32 Multithreaded Programing, published by O'Reilly. It has a jellyfish on the cover. It provides code for what you're trying to do. Take a look at their website to see if they have the code online. http://www.oreilly.com.
0
 
tflaiAuthor Commented:
Thank you for the quick response.  I'll see if my co-workers or anyone that I know has it.  (The website does not have online code on this topic.)
0
 
tflaiAuthor Commented:
Please wait for the grading till after I obtained the book.  Thanks.
0
 
tflaiAuthor Commented:
Got it.  A terrific book indeed.  Thanks!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now