Lisp HUG Maillist Archive

mp:with-lock lock ordering

Hi,
I am wondering if the order in which multiple threads calls the with-lock on a common lock is the order in which each thread gets the lock when the previous thread releases the lock. Or is it random?

For example if I have 3 threads called 1 2 3 respectively. if they lock the same lock using with-lock, will they be given the lock in the order of which called with-lock on the lock?

Thanks,

Quinn Jarrell

Re: mp:with-lock lock ordering

Hi Quinn,

.... just my 2cents... but (especially with SMP) it is probably a bad idea to expect any particular ordering...

- DM

On Feb 5, 2013, at 13:54 PM, quinn jarrell <quinnjarr@gmail.com> wrote:

> Hi,
> I am wondering if the order in which multiple threads calls the with-lock on a common lock is the order in which each thread gets the lock when the previous thread releases the lock. Or is it random?
> 
> For example if I have 3 threads called 1 2 3 respectively. if they lock the same lock using with-lock, will they be given the lock in the order of which called with-lock on the lock?
> 
> Thanks,
> 
> Quinn Jarrell

Dr. David McClain
CTO & Co-Founder
Acudora (TM)
e-mail: david@acudora.com
Tel: (+1) 520-529-2437




_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html


Re: mp:with-lock lock ordering

Speaking from an RTOS background, not LW, I would expect it to be either FIFO or priority based depending on how the lock is configured.  However, the make-lock function doesn't have any way to select FIFO vs priority.
http://www.lispworks.com/documentation/lw61/LW/html/lw-1057.htm#93763

Based on the description of LW process (which are really threads) scheduling, I would expect the highest priority task would get the lock first. 
http://www.lispworks.com/documentation/lw61/LW/html/lw-245.htm#marker-885999

All that said, I haven't actually dealt with this in LW, so I expect someone to come along with the right info.

And I agree with David that you should never expect particular ordering. 

Nick Patrick


On Tue, Feb 5, 2013 at 4:22 PM, David McClain <david@acudora.com> wrote:

Hi Quinn,

.... just my 2cents... but (especially with SMP) it is probably a bad idea to expect any particular ordering...

- DM

On Feb 5, 2013, at 13:54 PM, quinn jarrell <quinnjarr@gmail.com> wrote:

> Hi,
> I am wondering if the order in which multiple threads calls the with-lock on a common lock is the order in which each thread gets the lock when the previous thread releases the lock. Or is it random?
>
> For example if I have 3 threads called 1 2 3 respectively. if they lock the same lock using with-lock, will they be given the lock in the order of which called with-lock on the lock?
>
> Thanks,
>
> Quinn Jarrell

Dr. David McClain
CTO & Co-Founder
Acudora (TM)
e-mail: david@acudora.com
Tel: (+1) 520-529-2437




_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html


Updated at: 2020-12-10 08:35 UTC