[inmemory] Make inmemory thread safe