Hash table thread-safety
Victor Kryukov <victor.kryukov <at> gmail.com>
2008-02-19 02:57:12 GMT
I'm a bit confused about which hash tables operations are thread-safe
in SBCL - I know about locks, but I want to avoid them as much as
possible due to efficiency reasons. I'd appreciate if anybody would
tell me whether the following statements are true or false for the
latest x86-64 SBCL on the multi-core CPU. Even simple yes/no would be
fine; if you could provide some brief reasoning/implementation details
- that's even better. Feel free to refer me to any external sources of
information, of course.
1/ Multiple threads can safely read from the same hash table.
2/ Multiple threads can write to the same hash table. If two different
threads attempt to overwrite the same key simultaneously, the
resulting value (first or second one) is not specified, but it will be
one of the values provided, and no other problems would occur.
3/ Multiple threads can read and write to the same hash table. If one
thread attempts to read a value while another thread attempts to write
a new value, the value that reader gets (old or new) is not specified,
but the new value would be written, and no other problems would occur.
4/ Same as 2,3 above if one thread removes a key and another tries to
5/ Last, but not the least - I'd like to understand the behaviour of
maphash when other threads write to the hash-table. Is it true that
maphash is guaranteed about looping over all the _initial_ hash
elements, while behaviour for new added values is not specified?