added mutex lock, now only segfaults randomly on some shared_mem accesses