Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Programming Threads > Re: Understandi...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 16 of 16 Topic 4059 of 4146
Post > Topic >>

Re: Understanding pthread_cond_wait()

by "Chris M. Thomasson" <no@[EMAIL PROTECTED] > Sep 30, 2008 at 03:31 AM

<lancer6238@[EMAIL PROTECTED]
> wrote in message 
news:597b7a22-235d-4099-9302-ea0969b7b698@[EMAIL PROTECTED]
> On Sep 29, 5:49 am, "Chris M. Thomasson" <n...@[EMAIL PROTECTED]
> wrote:
>> "Chris M. Thomasson" <n...@[EMAIL PROTECTED]
> wrote in 
>> messagenews:PQSDk.4183$Bt7.1369@[EMAIL PROTECTED]
>>
>>
>>
>> > <lancer6...@[EMAIL PROTECTED]
> wrote in message
>>
>news:a099c363-65be-4a41-b080-03caadbddac1@[EMAIL PROTECTED]
>> [...]
>>
>> > So, do_Awork is a producer right?
>
> Yes.
>
>>
>> Please clarify... do_Awork and do_BCDwork can run concurrently within
the
>> global queue impl right? I am curious as to what the queue impl looks 
>> like.
>
> It's a circular queue. do_Awork and do_BCDwork should be able to run
> concurrently. Specifically, do_Awork puts items into the queue and
> do_BCDwork removes items from the queue. Ideally, do_Awork should
> write to the queue faster than do_BCDwork can read from the queue, and
> when this does not happen, i.e. do_BCDwork attempts to read an item
> that hasn't been written to the queue yet, it should wait till
> do_Awork has completed writing that item to the queue. Also, more than
> one thread should run do_BCDwork concurrently, with each thread
> reading a different item in the queue, and only one thread runs
> do_Awork.

If your sure that the queue itself does not have a bug, fine. If so, your 
experiencing a signaling bug. If not, well, ****%t happens and the queue 
needs to be "reexamined"...




>> > Humm... Well, a seg-fault does not always indicate a problem with 
>> > misusing
>> > a condvar. Your usually going to get a deadlock. If you think that
the
>> > misuse of a condvar is causing a seg-fault then its probably because 
>> > its
>> > allowing multiple threads to access a data-structure which simply 
>> > cannot
>> > tolerate it. Are you sure that the implementation of the global queue

>> > is
>> > correct? After you switch over to the semaphore solution proposes
>> > else-thread and run the program, are you still getting seg-faults?
For
>> > some reason, I think the problem may be in the global queue impl...
>
> The seg fault may also be caused by the consumer threads running
> do_BCDwork accessing an item in the queue that hasn't been completely
> written to the queue yet, because the consumer threads have been woken
> too early by the producer thread. I'm trying to correct this problem.

Well, using a semaphore like Szabolcs suggested would solve that. Since, 
according to you, do_Awork and do_BCDwork do not need to be under the 
protection of a common mutex, well, then a semaphore would be fine. Your 
consumers will not get signaled unless the producer has created something 
and _fully_ committed into the queue logic indeed. Have you tried using a 
semaphore? Do you still experience a seg-fault? Also, if your using POSIX 
semaphore, again, please keep in mind that the error condition `EINTR'
can, 
and probably WILL, occur every now and then...
 




 16 Posts in Topic:
Understanding pthread_cond_wait()
"lancer6238@[EMAIL P  2008-09-26 19:28:05 
Re: Understanding pthread_cond_wait()
"Chris M. Thomasson&  2008-09-26 21:19:14 
Re: Understanding pthread_cond_wait()
"lancer6238@[EMAIL P  2008-09-27 04:30:53 
Re: Understanding pthread_cond_wait()
Markus Elfring <Markus  2008-09-28 08:50:09 
Re: Understanding pthread_cond_wait()
"Chris M. Thomasson&  2008-09-28 14:33:19 
Re: Understanding pthread_cond_wait()
Szabolcs Ferenczi <sza  2008-09-28 04:26:13 
Re: Understanding pthread_cond_wait()
"Chris M. Thomasson&  2008-09-28 13:44:24 
Re: Understanding pthread_cond_wait()
"Chris M. Thomasson&  2008-09-29 04:59:37 
Re: Understanding pthread_cond_wait()
Szabolcs Ferenczi <sza  2008-09-28 13:56:49 
Re: Understanding pthread_cond_wait()
"Chris M. Thomasson&  2008-09-28 14:17:14 
Re: Understanding pthread_cond_wait()
Szabolcs Ferenczi <sza  2008-09-28 14:23:59 
Re: Understanding pthread_cond_wait()
"Chris M. Thomasson&  2008-09-28 14:38:36 
Re: Understanding pthread_cond_wait()
"Chris M. Thomasson&  2008-09-28 14:46:34 
Re: Understanding pthread_cond_wait()
"Chris M. Thomasson&  2008-09-28 14:49:40 
Re: Understanding pthread_cond_wait()
"lancer6238@[EMAIL P  2008-09-28 18:01:33 
Re: Understanding pthread_cond_wait()
"Chris M. Thomasson&  2008-09-30 03:31:51 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Nov 22 9:27:02 CST 2008.