This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author tim.peters
Recipients
Date 2001-06-19.22:06:04
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
Logged In: YES 
user_id=31435

> The problem will be arised if there is a thread 3
> called PyThread_acquire_lock 

You never mentioned thread 3 again, so I don't know what it 
has to do with this.

> after thread 1 set thelock->locked to 0 and before
> thread 2 calling pthread_mutex_lock. 

I understand both of those.  Are you assuming that, e.g., 
thread 3's PyThread_acquire_lock completes in whole during 
this gap?  I don't know what else you could mean, so let's 
assume that.

> "while (thelock->locked)" will success for thread 2

Sure.

> and it will call pthread_cond_wait

Yup.

> and might collide with thread 1's pthread_cond_signal.

What does "collide" mean to you?  All the pthread_cond_xxx 
functions must be implemented as if atomic, so there's no 
meaningful sense (to me) in which they can collide -- 
unless they're implemented incorrectly.

Assuming they are implemented correctly, it again doesn't 
matter that thread 2 misses thread 1's signal, because 
thread *3* exploited the information thread 1 was going to 
signal, by acquiring the lock.  It's actually good that 
thread 2 isn't bothered with it:  there's no real info in 
the signal anymore (at best, if thread 2 got it, it would 
wake up and go "oops! it's still locked; I'll wait again").

All that matters now is whether thread 2 gets a chance to 
see thread *3*'s signal, at the time thread 3 releases the 
lock.  And it will, because thread 3 can't release the lock 
without acquiring the mutex first, and thread 2 holds the 
mutex at all times except when in its pthread_cond_wait 
call (so thread 3 can't release the lock except when thread 
2 is in pthread_cond_wait).

Note that I'm not at all concerned about "fairness" here, 
only about races.
History
Date User Action Args
2007-08-23 13:54:51adminlinkissue433625 messages
2007-08-23 13:54:51admincreate