From: jaialai technology on
I am using pthread mutexes. I have, say, 8 threads.
5 are A threads. 2 are B threads. there is 1 C thread.
A, B, and C all try and lock the same mutex.
What I am seeing is that the A and B threads
seem to never allow C to go.
Is there a better way to handle this?
I am somewhat new to this so maybe I just
need a pointer to a better construct than
a mutex. I tried a condition variable
that C would wait for and A and B would
signal but that didn't seem to work either.
From: David Schwartz on
On Dec 8, 11:40 am, jaialai technology <jaialai.technol...(a)gmail.com>
wrote:

> I am using pthread mutexes. I have, say, 8 threads.
> 5 are A threads. 2 are B threads. there is 1 C thread.
> A, B, and C all try and lock the same mutex.
> What I am seeing is that the A and B threads
> seem to never allow C to go.
> Is there a better way to handle this?

If you care which thread gets the resource, don't use a mutex.

> I am somewhat new to this so maybe I just
> need a pointer to a better construct than
> a mutex. I tried a condition variable
> that C would wait for and A and B would
> signal but that didn't seem to work either.

What is your outer problem? Why do you have something with so much
contention? And why do you care who gets the resource -- every thread
should be able to make useful forward progress or it should be
blocked.

You should not have a whole bunch of threads that spin tightly around
a single resource. That just indicates a poor choice of where to draw
the lines between your threads.

DS
From: Eric Sosman on
jaialai technology wrote:
> I am using pthread mutexes. I have, say, 8 threads. 5 are A threads. 2
> are B threads. there is 1 C thread.
> A, B, and C all try and lock the same mutex.
> What I am seeing is that the A and B threads
> seem to never allow C to go.
> Is there a better way to handle this?
> I am somewhat new to this so maybe I just
> need a pointer to a better construct than
> a mutex. I tried a condition variable
> that C would wait for and A and B would
> signal but that didn't seem to work either.

You seem to misunderstand what mutexes and condition
variables are, and what they're for -- they are not at all
alike. The fact that you would even think of trying to
substitute one for the other suggests that you don't quite
know what you're doing, much as if you'd asked what size
spare tire you should use for your steering wheel ... No
insult intended; everyone was new to this stuff sometime.

Without seeing what you've done, I don't know what sort
of change to advise. Can you try whittling your program down,
cutting away all the parts that don't bear directly on the
problem, and then posting the cut-down code? (Before posting,
please make sure that it compiles, and that it still has the
problem that's plaguing you.) Given some code to study, I
imagine the experts here might muster some help.

--
Eric Sosman
esosman(a)ieee-dot-org.invalid
 | 
Pages: 1
Prev: Shariffa Carlo
Next: makefile debug release