develooper Front page | perl.ithreads | Postings from May 2009

deadlocking on high cpu usage?

Thread Next
From:
Zenko Klapko Jr.
Date:
May 18, 2009 14:16
Subject:
deadlocking on high cpu usage?
Message ID:
162a15970905181416u12aad8ddm59be2af3b9805aff@mail.gmail.com
Hi,

I have a perl script that gathers some data initially in the main thread,
then farms out work to helper threads. I have two shared variables, each
controlling access to a separate library. Never do I lock() both in the same
sub-block, and even if I did I would make sure I did it in the same order.
Under low cpu usage (when the script runs by itself) everything works out.
Under high cpu usage (run yes) the perl script appears to deadlock. I took a
look at the script under strace and its stuck on futex. I'm wondering if my
code is to blame and the deadlock only appears under high cpu usage. Any
help (pointing out my terrible code counts) is appreciated!

Main Thread->GathersInfo()->Launch 5 Worker Threads->End

WorkerThreadSub()
{

if($possiblyTrue)
{lock($a)
launch thread with library
join()
}

{ lock($b)
launch thread with other library
join()
}

if($possiblyTrue)
{lock($a)
launch thread with library
join()
}
...stuff...
#end WorkerThread
}

-Zenko
-- 
I would rather be exposed to the inconveniences attending too much liberty
than to those attending too small a degree of it.
 - Thomas Jefferson

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About