Lisp HUG Maillist Archive

"Synchronized" operations

Hi!

By chance I came across this text in the LW Reference Manual where
MP:CREATE-SIMPLE-PROCESS is explained:

  "Other Common Lisp functions might not work if they attempt to
   block. This applies in particular to I/O functions on streams such
   as pipes and to (setf gethash) on a hash table that another process
   is mapping over."

From this I gather that hash tables are kind of "synchronized" (to use
a Java term) with respect to multiprocessing.  What I couldn't find is
a place in the manuals where this is explained in detail.  The word
"hash", e.g., doesn't occur in the User Guide chapter about
multiprocessing.

So, where can I find out more?  Does this mean that if I work with
hash tables I don't have to introduce locks myself if several threads
are tring to modify the hash tables?  Are all ways of mapping over a
hash table (MAPHASH, WITH-HASH-TABLE-ITERATOR, LOOP) treated the same
way?  Is (SETF GETHASH) an "atomic" operation, kind of?  Are there
other Lisp data structures that are somehow special as far as MP is
concerned?  Is there a list of "atomic" operations somewhere?

Thanks,
Edi.


Re: "Synchronized" operations

Edi Weitz <edi@agharta.de> writes:

> Does this mean that if I work with
> hash tables I don't have to introduce locks myself if several threads
> are tring to modify the hash tables?  

Yes, hash tables are thread-safe. Btw. I've learned the hard way
that mapping over hash tables may be a bad idea in multi-threaded
servers. It took me some serious debugging before I discovered
what an utterly bad idea it was to include slow things like data-
base access inside a maphash on a table that was being used by
more than 50 threads...
-- 
  (espen)


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