|
Home > Archive > Unix Programming > October 2006 > Threading question - Please help
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Threading question - Please help
|
|
| cpptutor2000@yahoo.com 2006-10-22, 7:19 pm |
| I am trying to create an application with three threads, of which 2 are
of the same type. The first periodically updates a number, the other
two read this value and does some other operations. I am using pthread,
and mutexes for all reads and writes. I am having a problem with the
threads that read the data item incremented by the first thread in that
when the application starts up, both of them start, but later I see one
overriding the other - one thread keeps generating the correct result,
while I see no output from the other. I have print statements to
indicate what is going on. Could someone please suggest how to correct
this? Thanks in advance for your help.
| |
| Pascal Bourguignon 2006-10-22, 7:19 pm |
| "cpptutor2000@yahoo.com" <cpptutor2000@yahoo.com> writes:
> I am trying to create an application with three threads, of which 2 are
> of the same type. The first periodically updates a number, the other
> two read this value and does some other operations. I am using pthread,
> and mutexes for all reads and writes. I am having a problem with the
> threads that read the data item incremented by the first thread in that
> when the application starts up, both of them start, but later I see one
> overriding the other - one thread keeps generating the correct result,
> while I see no output from the other. I have print statements to
> indicate what is going on. Could someone please suggest how to correct
> this? Thanks in advance for your help.
Probably both threads are overriding the same output buffer.
Accesses to unique unix resources should be serialized too.
Use a mutex around printf and all other non-thread savvy library.
--
__Pascal Bourguignon__ http://www.informatimago.com/
"This machine is a piece of GAGH! I need dual Opteron 850
processors if I am to do battle with this code!"
| |
| David Schwartz 2006-10-24, 7:21 am |
|
cpptutor2000@yahoo.com wrote:
> I am trying to create an application with three threads, of which 2 are
> of the same type. The first periodically updates a number, the other
> two read this value and does some other operations. I am using pthread,
> and mutexes for all reads and writes. I am having a problem with the
> threads that read the data item incremented by the first thread in that
> when the application starts up, both of them start, but later I see one
> overriding the other - one thread keeps generating the correct result,
> while I see no output from the other. I have print statements to
> indicate what is going on. Could someone please suggest how to correct
> this? Thanks in advance for your help.
This is a version of "can you find the bug in some code that I didn't
post?" Post your code, we'll find the bug in it.
DS
|
|
|
|
|