Producer-comsumer threads using semaphore mutex

This is a discussion on Producer-comsumer threads using semaphore mutex within the C Programming forums, part of the General Programming Boards category; Hey! Ive been programming for a little while and i need help! I need to produce code so that a ...

  1. #1
    Registered User
    Join Date
    Apr 2004
    Posts
    2

    Producer-comsumer threads using semaphore mutex

    Hey!
    Ive been programming for a little while and i need help!

    I need to produce code so that a producer thread can generate an integer between 0 and 9, store it in a file and dispaly the number on the screen. After the generation the producer sleeps for a random amount of time between 0 and 100 miliseconds before reapeating the number generation.

    The consumer thread being ravenous, consumes all integers from the file as quickly as the become available. The producer must have a way of indicating to the consumer that a value is ready and teh consumer must have a way of indicating that the value has been retrieved.

    I need to use wait() and signal() functions and semaphore mutex but i really dont know how. I would really be grateful if anyone could tell me where i could get such code.

    Thanks alot

    Kaiya xx

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    What have you done so far yourself?
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683
    Is the language you are using Pascal FC by any chance...

  4. #4
    Registered User
    Join Date
    Nov 2003
    Posts
    12
    wait() and signal() are for condition variables. Basically you want the consumer to wait on the variable and "consume" whenever it is signalled. You also want the producer to signal on the variable whenever it has "produced" something.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 05-08-2008, 09:50 AM
  2. Replies: 1
    Last Post: 06-11-2007, 04:59 PM
  3. CreateSemaphore/ReleaseSemaphore
    By nrieger in forum Windows Programming
    Replies: 2
    Last Post: 08-03-2005, 06:57 AM
  4. semaphore or mutex
    By Micko in forum Windows Programming
    Replies: 2
    Last Post: 07-05-2004, 10:39 AM
  5. Mutex vs. Semaphore
    By cjschw in forum C++ Programming
    Replies: 1
    Last Post: 07-22-2003, 07:03 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21