Safe work with shared memory