added dynamic pthread thread local storage (alternative to #827)