[mem] Added semaphores. Made memory managers thread safe(r).