Fix issue #24: move initialization of thread synchronization objects befor the first call of free_context