[LCP]Help in Threads

David filiond at videotron.ca
Wed Nov 20 21:56:02 UTC 2002


Mohd Saifullah wrote:
> Greetings to All!
> 
> I have written two threads (Linux pthreads). One thread does "ping"ing for
> two to three secs. The other thread has to note down the interface traffic
> count at the beginning of the pinging and also at the end of it, so this
> thread has 2 secs sleep in between the two readings. But the problem is:  
> first thread is executed completely and then control comes to second 
> thread. But i want control to switch from first thread to second thread as
> soon as first one starts pinging.
> 
> Thanks in advance,
> Saif
> 

Have you thought using a condition variable?  You could use it make the 
first thread signal the second and wait until the second thread completes.
The second thread could then signal the first when it is finished.

-- 
David Filion
Registerd (Slackware) linux user #195143

"Yes, it's manly, but let's face it, so is bungee-jumping with the
  cord tied to your testicles." -- Linus Torvalds




More information about the linuxCprogramming mailing list