Works in one thread, 2 threads => segfault