[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

libpcap/pthread problem



Hello everyone,

I have recently encountered a problem with a threaded
application using pcap. The basic idea is that one
thread would capture packets with pcap and pass them
via a queue to a second thread wich will compute some
traffic statistics. The second thread sleeps in a
loop, waking up periodically to check for packets in
the queue.
The problem is, once the 2nd thread goes to sleep, it
never wakes up. I've tried to use sleep, pause,
sigsuspend, sigwait (with the 1st thread signalling
it); none of these work.
There is one case, though, when the application works
fine: when passing 0 as the 4th argument (timeout) to
pcap_open_live. But in this case, the 1st thread sits
in a busy loop, resulting in a 100% CPU utilization
(as reported by top), which is not acceptable.
I've attached attached the relevant code.

Am I missing something, or is this a system bug (or
the intended behaviour?)
Any help would be greatly appreciated.
Best regards,
Dan.
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

[demime 0.98d removed an attachment of type application/x-tgz which had a name of traffic_stat_demo.tgz]