Repository: godot
Issue: Data races when running Godot
Labels: bug,topic:core

**Godot version:**
3.2.alpha.custom_build. 24e1039eb

**OS/device including version:**
Ubuntu 19.04

**Issue description:**
When I run Godot project manager, then thread sanitizer shows some data races(reading data in one thread, when saving in another thread)
- Log from project manager - [AAAA.txt](https://github.com/godotengine/godot/files/3597218/AAAA.txt)
```
WARNING: ThreadSanitizer: data race (pid=27914)
  Atomic write of size 8 at 0x0000092a1ec0 by thread T1:
    #0 __tsan_atomic64_fetch_add <null> (godot.x11.tools.64.llvms+0x1703076)
    #1 unsigned long atomic_add<unsigned long, unsigned long>(unsigned long volatile*, unsigned long) /home/rafal/Pulpit/mojgodot/./core/safe_refcount.h:136:9 (godot.x11.tools.64.llvms+0x666442b)
    #2 Memory::alloc_static(unsigned long, bool) /home/rafal/Pulpit/mojgodot/core/os/memory.cpp:98 (godot.x11.tools.64.llvms+0x666442b)
    #3 operator new(unsigned long, char const*) /home/rafal/Pulpit/mojgodot/core/os/memory.cpp:42:9 (godot.x11.tools.64.llvms+0x6664268)
    #4 ThreadPosix::thread_callback(void*) /home/rafal/Pulpit/mojgodot/drivers/unix/thread_posix.cpp:70:45 (godot.x11.tools.64.llvms+0x2d3e899)

  Previous read of size 8 at 0x0000092a1ec0 by main thread:
    #0 Memory::alloc_static(unsigned long, bool) /home/rafal/Pulpit/mojgodot/core/os/memory.cpp:99:42 (godot.x11.tools.64.llvms+0x6664441)
    #1 CowData<wchar_t>::resize(int) /home/rafal/Pulpit/mojgodot/./core/cowdata.h:274:32 (godot.x11.tools.64.llvms+0x22ceb5b)
    #2 String::resize(int) /home/rafal/Pulpit/mojgodot/./core/ustring.h:154:45 (godot.x11.tools.64.llvms+0x2efe9d4)
    #3 String::copy_from(char const*) /home/rafal/Pulpit/mojgodot/core/ustring.cpp:169:2 (godot.x11.tools.64.llvms+0x64bc814)
    #4 String::operator=(char const*) /home/rafal/Pulpit/mojgodot/core/ustring.cpp:331:2 (godot.x11.tools.64.llvms+0x64bd758)
    #5 detect_prime() /home/rafal/Pulpit/mojgodot/platform/x11/detect_prime.cpp:135:15 (godot.x11.tools.64.llvms+0x1782c12)
    #6 OS_X11::initialize(OS::VideoMode const&, int, int) /home/rafal/Pulpit/mojgodot/platform/x11/os_x11.cpp:275:16 (godot.x11.tools.64.llvms+0x174b148)
    #7 Main::setup2(unsigned long) /home/rafal/Pulpit/mojgodot/main/main.cpp:1117:35 (godot.x11.tools.64.llvms+0x17bade5)
    #8 Main::setup(char const*, int, char**, bool) /home/rafal/Pulpit/mojgodot/main/main.cpp:1062:10 (godot.x11.tools.64.llvms+0x17b9f28)
    #9 main /home/rafal/Pulpit/mojgodot/platform/x11/godot_x11.cpp:49:14 (godot.x11.tools.64.llvms+0x1744730)

  Location is global 'Memory::mem_usage' of size 8 at 0x0000092a1ec0 (godot.x11.tools.64.llvms+0x0000092a1ec0)

  Thread T1 (tid=27916, running) created by main thread at:
    #0 pthread_create <null> (godot.x11.tools.64.llvms+0x16b90d5)
    #1 ThreadPosix::create_func_posix(void (*)(void*), void*, Thread::Settings const&) /home/rafal/Pulpit/mojgodot/drivers/unix/thread_posix.cpp:90:2 (godot.x11.tools.64.llvms+0x2d3eadf)
    #2 Thread::create(void (*)(void*), void*, Thread::Settings const&) /home/rafal/Pulpit/mojgodot/core/os/thread.cpp:51:10 (godot.x11.tools.64.llvms+0x666c8b0)
    #3 IP::IP() /home/rafal/Pulpit/mojgodot/core/io/ip.cpp:326:22 (godot.x11.tools.64.llvms+0x679c0df)
    #4 IP_Unix::IP_Unix() /home/rafal/Pulpit/mojgodot/drivers/unix/ip_unix.cpp:265:10 (godot.x11.tools.64.llvms+0x2f208dc)
    #5 IP_Unix::_create_unix() /home/rafal/Pulpit/mojgodot/drivers/unix/ip_unix.cpp:262:9 (godot.x11.tools.64.llvms+0x2f2085b)
    #6 IP::create() /home/rafal/Pulpit/mojgodot/core/io/ip.cpp:310:9 (godot.x11.tools.64.llvms+0x679bde3)
    #7 register_core_types() /home/rafal/Pulpit/mojgodot/core/register_core_types.cpp:211:7 (godot.x11.tools.64.llvms+0x641b468)
    #8 Main::setup(char const*, int, char**, bool) /home/rafal/Pulpit/mojgodot/main/main.cpp:341:2 (godot.x11.tools.64.llvms+0x17abf12)
    #9 main /home/rafal/Pulpit/mojgodot/platform/x11/godot_x11.cpp:49:14 (godot.x11.tools.64.llvms+0x1744730)

SUMMARY: ThreadSanitizer: data race (/home/rafal/Pulpit/mojgodot/bin/godot.x11.tools.64.llvms+0x1703076) in __tsan_atomic64_fetch_add
```


**Steps to reproduce:**
1. Compile Godot with thread sanitizer support e.g.(newer versions of GCC compiler are a little buggy for now, so llvm is the only option)
```
scons p=x11 -j6 use_tsan=yes use_llvm=yes
```
2. Run project manager
```
bin/godot.x11.tools.64.llvms
```