Skip to content

Multithreaded concept

malex984 edited this page Oct 1, 2012 · 23 revisions

Multithreaded concept for our multi-library SW setting:

  • Some of our libraries need their own TLS
  • xthread should provide the basic support for C++:
    • Common TLS Structure that accommodates places for all of our libs: void* lib_tls[MAXLIBID] = 0,0,0...0;
    • Common TLS macros for getting at it
    • new_thread, which should take Init and Done as well as run function pointers for setting up TLS for all the needed Libs: in their dependency order!
    • LIBIDs as #define's

Small steps (plan):

  • Start with SW
  • Make sure findexec is used readonly and thus is thread-safe
  • Cristian makes his variant of omalloc - thread-safe
  • since factory is not thread-safe and uses NTL - guard all the calls into factory with a lock: TODO for a HiWi, this should better be ifdef'ed depending on HAVE_THREADS(!?)
  • the rest of our libs: libpolys, kernel, Singular (numeric?) should make use of the above "Multi-library concept":
    1. identify all the global variables
    2. Document all readonly global variables (with a single global initialization)
    3. Guard shared ones with locks if they are not readonly vars: examples?
    4. The rest should be put into LIBTLS Structure for that lib. - but first we simply assume that we have "__thread" and mark them with this directive, maybe using a conditionaly defined macro __THREAD, depending on HAVE_THREADS. Examples: currRing, options (value/test)...
    5. Each lib should provide its own Init/Done_lib global functions that are supposed to know about corresponding functions for underlying libraries, and should call them in correct order: easy with the left libraries(?)
    6. Each library should have its own TLS macro and access thread local variables via: TLS().variable