-4

I have two threads. one thread generate a number and the other squares the number generated. I need to synchronise this action using pipes or semaphore or message queues . Help me with this problem

  • 1
    Hi and welcome. this is not the right way to ask a question. did you google your problem? did you try to program something yourself?it'll be difficult to find someone to just give you ready code to solve your problem. read this http://mattgemmell.com/2008/12/08/what-have-you-tried/ good luck – Moataz Elmasry Aug 01 '12 at 14:15
  • If you have threads in the very same process, you can use condition variables if they are available on your system. – Torsten Robitzki Aug 01 '12 at 14:32

1 Answers1

1

This is a wrong way to go. Generating an extra thread and synchronizing the two threads would require more CPU power than just squaring the number in the generator thread.

Implementing a pipeline is effective only when each step requires enough computational power to justify the extra thread.

As for your questions, I suggest you should read about the Producer-Consumer pattern. There are many implementations on the wild.

Lior Kogan
  • 19,919
  • 6
  • 53
  • 85