XboxDev / nxdk-libcxx

Copy of libcxx git repository located at http://llvm.org/git/libcxx (adapted for original Xbox / nxdk toolchain)
http://libcxx.llvm.org
Other
4 stars 3 forks source link

Add C++11 thread support #2

Closed thrimbor closed 4 years ago

thrimbor commented 4 years ago

Enables support for C++11 threads, based on the Win32 threads backend. Depends on https://github.com/XboxDev/nxdk/pull/274.

Minor modifications are done to adjust libc++ for nxdk-specific details, such as condition variables being a different size than on Windows. It also uses DestroyConditionVariable, which is an nxdk-specific addition to prevent leaking event handles (Windows Vista and newer have kernel mechanisms that allow for an implementation of condition variables that doesn't require the creation of events, so this is not an issue there).

It can be tested with something like this (don't forget NXDK_CXX=y ofc):

  std::thread t([] {
    debugPrint("hello!\n");
    Sleep(5000);
    debugPrint("done!\n");
  });

  t.join();
  debugPrint("thread done\n");
thrimbor commented 4 years ago

Just pushed a small update to fix compatibility with the DestroyConditionVariable -> UninitializeConditionVariable rename.

JayFoxRox commented 4 years ago

Tests by others (maintainers, contributors and users alike) would be welcome. I plan to merge this soon; most of the implementation has been part of https://github.com/XboxDev/nxdk/pull/274, so we mostly need a quick review and someone to say "Works" (after testing).

GXTX commented 4 years ago

Tested this today after writing some bad code, seems to work as expected. image See bad code

dracc commented 4 years ago

Tested with this code: https://hastebin.com/yebiwokize.cpp Got this result: screenshot

Same code works fine without the changes of this pull request.

dracc commented 4 years ago

Tested with the thrimborfixes branch of NevolutionX, works as expected. :+1: