Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

adding slots to locks?

47 views
Skip to first unread message

Florian Dietz

unread,
Jun 15, 2013, 5:35:30 AM6/15/13
to
I am trying to add a new slot to the lock class. This is useful because I have a lot of locks in a hierarchy and if I store that parent lock for every lock it becomes easier to detect problems while debugging.

Unfortunately, this apparently can't be done with the ensure-class function. I can add slots to 'process, but not to 'lock, because it is listed as a built-in-class.

Do you know how to solve this problem?
If it is not possible, the only alternative I can think of is storing the hierarchical relation of locks in a hash-table, but since some of the locks are created at runtime and in different processes, I would have to add yet another lock just to access the hashtable that stores metadata on the locks.

This strikes me as terribly inefficient. Do you have a better idea?

Paul Rubin

unread,
Jun 15, 2013, 5:44:08 AM6/15/13
to
Florian Dietz <florian...@googlemail.com> writes:
> Unfortunately, this apparently can't be done with the ensure-class
> function. I can add slots to 'process, but not to 'lock, because it is
> listed as a built-in-class. Do you know how to solve this problem?

See the implementation of RLock in the threading library. Does that help?

Pascal Costanza

unread,
Jun 15, 2013, 5:46:26 AM6/15/13
to
1) Please specify which Lisp implementation you are using. Locks are not
standardized, so what you want to do may depend a lot on the concrete
implementation.

2) Can you subclass the lock class, or define a new struct that includes
the lock struct? Maybe this is good enough for your purposes if you are
able to use your own extension without messing with the internals of an
existing class or struct. The latter may have unexpected consequences.

3) Many Lisp implementations provide lock-free hashtables that guarantee
consistency in parallel / multi-threaded environments without the need
to use locks. I'm pretty sure that LispWorks and Clozure support this,
but there are quite likely others as well. Also consider using weak
hashtables, so you don't prevent the locks from being garbage-collected.

Pascal


--
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/
The views expressed are my own, and not those of my employer.

Florian Dietz

unread,
Jun 15, 2013, 5:53:34 AM6/15/13
to
I am using Clozure.
Does it have a good lock-free hash-table?

Pascal Costanza

unread,
Jun 15, 2013, 6:17:47 AM6/15/13
to
On 15/06/2013 11:53, Florian Dietz wrote:
> I am using Clozure.
> Does it have a good lock-free hash-table?

At least that's how they advertize it. I haven't tried myself though.

Florian Dietz

unread,
Jun 15, 2013, 6:27:02 AM6/15/13
to
what is it called? I have googled it, but can't find anything besides theory.

Pascal Costanza

unread,
Jun 15, 2013, 10:09:41 AM6/15/13
to
On 15/06/2013 12:27, Florian Dietz wrote:
> what is it called? I have googled it, but can't find anything besides theory.

It seems indeed hard to find. I only found this:
http://trac.clozure.com/ccl/wiki/Internals/LockFreeHashTables

Maybe ask in their mailing list.

Pascal J. Bourguignon

unread,
Jun 15, 2013, 2:04:08 PM6/15/13
to
Well, most CL implementations are free software. Don't be afraid to
patch them. And even if writing a CDR, and half a dozen patch would be
more work than just (add-slot '<class> '(<slot> :accessor <slot>)), it
think it would be worthwhile.


--
__Pascal Bourguignon__ http://www.informatimago.com/
A bad day in () is better than a good day in {}.
You know you've been lisping too long when you see a recent picture of George
Lucas and think "Wait, I thought John McCarthy was dead!" -- Dalek_Baldwin

R. Matthew Emerson

unread,
Jun 15, 2013, 4:29:48 PM6/15/13
to
Florian Dietz <florian...@googlemail.com> writes:

> I am using Clozure.
> Does it have a good lock-free hash-table?

Clozure CL's hash tables are thread-safe (and lock-free) by default.

If you don't want the hash table implementation to use the lock-free
algorithm and use locks instead, you can pass :lock-free nil to
make-hash-table.

The lock-free algorithm is faster for typical access, but slower for
rehashing or growing the table.
0 new messages