Re: Question regarding mutex locking

2007-11-29 Thread Bryan O'Sullivan
Larry Finger wrote: If a particular routine needs to lock a mutex, but it may be entered with that mutex already locked, would the following code be SMP safe? hold_lock = mutex_trylock() The common way to deal with this is first to restructure your function into two. One always acquires the

Re: Question regarding mutex locking

2007-11-28 Thread Jarek Poplawski
On 29-11-2007 03:34, David Schwartz wrote: >> Thanks for the help. Someday, I hope to understand this stuff. >> >> Larry > > Any code either deals with an object or it doesn't. If it doesn't deal with > that object, it should not be acquiring locks on that object. If it does > deal with that objec

Re: Question regarding mutex locking

2007-11-28 Thread Jarek Poplawski
On Wed, Nov 28, 2007 at 03:33:12PM -0800, Stephen Hemminger wrote: ... > WTF are you teaching a lesson on how NOT to do locking? > > Any code which has this kind of convoluted dependency on conditional > locking is fundamentally broken. > As a matter of fact I've been thinking, about one more Re

RE: Question regarding mutex locking

2007-11-28 Thread David Schwartz
> Thanks for the help. Someday, I hope to understand this stuff. > > Larry Any code either deals with an object or it doesn't. If it doesn't deal with that object, it should not be acquiring locks on that object. If it does deal with that object, it must know the internal details of that object,

Re: Question regarding mutex locking

2007-11-28 Thread Stephen Hemminger
On Wed, 28 Nov 2007 23:45:13 +0100 Jarek Poplawski <[EMAIL PROTECTED]> wrote: > Larry Finger wrote, On 11/28/2007 04:41 PM: > > > Andreas Schwab wrote: > >> Larry Finger <[EMAIL PROTECTED]> writes: > >> > >>> If a particular routine needs to lock a mutex, but it may be entered with > >>> that mu

Re: Question regarding mutex locking

2007-11-28 Thread Jarek Poplawski
Jarek Poplawski wrote, On 11/28/2007 11:56 PM: > Jarek Poplawski wrote, On 11/28/2007 11:45 PM: > >> Larry Finger wrote, On 11/28/2007 04:41 PM: >> >>> Andreas Schwab wrote: Larry Finger <[EMAIL PROTECTED]> writes: > If a particular routine needs to lock a mutex, but it may be enter

Re: Question regarding mutex locking

2007-11-28 Thread Jarek Poplawski
Jarek Poplawski wrote, On 11/28/2007 11:45 PM: > Larry Finger wrote, On 11/28/2007 04:41 PM: > >> Andreas Schwab wrote: >>> Larry Finger <[EMAIL PROTECTED]> writes: >>> If a particular routine needs to lock a mutex, but it may be entered with that mutex already locked, would the f

Re: Question regarding mutex locking

2007-11-28 Thread Jarek Poplawski
Larry Finger wrote, On 11/28/2007 04:41 PM: > Andreas Schwab wrote: >> Larry Finger <[EMAIL PROTECTED]> writes: >> >>> If a particular routine needs to lock a mutex, but it may be entered with >>> that mutex already locked, >>> would the following code be SMP safe? >>> >>> hold_lock = mutex_trylo

Re: Question regarding mutex locking

2007-11-28 Thread Larry Finger
Andreas Schwab wrote: > Larry Finger <[EMAIL PROTECTED]> writes: > >> If a particular routine needs to lock a mutex, but it may be entered with >> that mutex already locked, >> would the following code be SMP safe? >> >> hold_lock = mutex_trylock() >> >> ... >> >> if (hold_lock) >> mutex_unl

Re: Question regarding mutex locking

2007-11-28 Thread Andreas Schwab
Larry Finger <[EMAIL PROTECTED]> writes: > If a particular routine needs to lock a mutex, but it may be entered with > that mutex already locked, > would the following code be SMP safe? > > hold_lock = mutex_trylock() > > ... > > if (hold_lock) > mutex_unlock() When two CPUs may enter the

Re: Question regarding mutex locking

2007-11-28 Thread Matthias Kaehlcke
El Wed, Nov 28, 2007 at 08:46:51AM -0600 Larry Finger ha dit: > Matthias Kaehlcke wrote: > > El Tue, Nov 27, 2007 at 10:37:00PM -0600 Larry Finger ha dit: > > > >> If a particular routine needs to lock a mutex, but it may be entered with > >> that mutex already locked, > >> would the following c

Re: Question regarding mutex locking

2007-11-28 Thread Larry Finger
Matthias Kaehlcke wrote: > El Tue, Nov 27, 2007 at 10:37:00PM -0600 Larry Finger ha dit: > >> If a particular routine needs to lock a mutex, but it may be entered with >> that mutex already locked, >> would the following code be SMP safe? >> >> hold_lock = mutex_trylock() >> >> ... >> >> if (hold

Re: Question regarding mutex locking

2007-11-28 Thread Matthias Kaehlcke
El Tue, Nov 27, 2007 at 10:37:00PM -0600 Larry Finger ha dit: > If a particular routine needs to lock a mutex, but it may be entered with > that mutex already locked, > would the following code be SMP safe? > > hold_lock = mutex_trylock() > > ... > > if (hold_lock) > mutex_unlock() this

Re: Question regarding mutex locking

2007-11-27 Thread Larry Finger
Robert Hancock wrote: > Larry Finger wrote: >> If a particular routine needs to lock a mutex, but it may be entered >> with that mutex already locked, >> would the following code be SMP safe? >> >> hold_lock = mutex_trylock() >> >> .. >> >> if (hold_lock) >> mutex_unlock() > > Not if another t

Re: Question regarding mutex locking

2007-11-27 Thread Robert Hancock
Larry Finger wrote: If a particular routine needs to lock a mutex, but it may be entered with that mutex already locked, would the following code be SMP safe? hold_lock = mutex_trylock() .. if (hold_lock) mutex_unlock() Not if another task could be acquiring that lock at the same ti