[CLN-list] thread-safety for CLN

Bruno Haible bruno at clisp.org
Wed Nov 22 17:49:00 CET 2006


Hello,

> I am presently working on a port of code-libraries which make extensive use
> of CLN to multi-threaded code (e.g. using OpenMP or explicit "by hand"
> threading), for use on multi-core and SMP systems.  

This is a very good idea. OpenMP allows to make use of multiple processors
with very little programming effort. And gcc-4.2 will support it.

> CLN release 1.1.13 is not re-entrant, and as far as I can tell from
> preliminary evaluation (and a large number of tests which produce major
> heap corruption), this is primarily because of the non-atomic reference
> counting (and possibly other mechanisms that I have not yet located).

You could probably easily replace this with atomic increments and decrements;
it's centralized in the three methods
  cl_inc_pointer_refcount
  cl_gc_dec_pointer_refcount
  cl_rc_dec_pointer_refcount
in include/cln/object.h. It will need a few CPU specific asms in order to
be efficient.

Furthermore you have to minimize/eliminate the global variables in cl_low.h.

Also some cl_hash* tables might need locking.

There are also a few global variables, such as the default precision and
the input/output radix. Probably they are only modified at the start of
any cln application.

All in all, it's quite feasible, because most of CLN is written in a functional
style and uses parameter passing on the stack.

Bruno


More information about the CLN-list mailing list