google / googletest

GoogleTest - Google Testing and Mocking Framework
https://google.github.io/googletest/
BSD 3-Clause "New" or "Revised" License
34.77k stars 10.15k forks source link

Support multithreading on non-POSIX platforms #2380

Open kuzkry opened 5 years ago

kuzkry commented 5 years ago

I've got an idea to leverage the fact that we use C++11.

In primer.md there is a known limitation that has been around since 642acb (more than 4 years old) and it suggests to write custom platform-specific implementations for concurrency support. Quote:

Google Test is designed to be thread-safe. The implementation is thread-safe on systems where the pthreads library is available. It is currently unsafe to use Google Test assertions from two threads concurrently on other systems (e.g. Windows). In most tests this is not an issue as usually the assertions are done in the main thread. If you want to help, you can volunteer to implement the necessary synchronization primitives in gtest-port.h for your platform.

Now, after we've finally switched to C++11, I suppose it's high time to do it right and have one, portable implementation which will work everywhere. I've started working on a new pull request that will deal with it, though it's not that easy and it's presumably going to take some longer time.

@gennadiycivil - please let me know if you have insight against it.

EricWF commented 5 years ago

@kuzkry Thanks for raising this issue. As you rightly state, C++11 should provide us with everything we need to make this work (I think; famous last words).

But I don't have any context on this issue, so instead of fumbling my way to a real test case, can you provide one? I'm assuming you have a broken test that lead you here.

kuzkry commented 5 years ago

No, I don't have it. I run Linux so those thing work for me. I guess it may be challenging to provide one on a multithreaded environment.

I accidentally stumbled upon this while I was reading docs and content of gtest-port.h and I wasn't certain if old implementation is deliberately kept (because maybe someone had already proposed a similar thing and it'd been turned down).

diegohavenstein commented 4 years ago

Hi @kuzkry have you worked on this, or did it slip down in your personal backlog?

kuzkry commented 4 years ago

Hi @diegohavenstein, don't worry, I'm on it. I just wasn't very active last 3-4 months but it definitely didn't slip down ;)

kuzkry commented 4 years ago

@diegohavenstein, just to let you know, I've got the gist of it working :). I yet need to make myself a meticulous self code review, clean-up some garbage etc. before I submit a pull request.

However, I wanted to let you know that it's going to take a lot of time before it gets merged (if it will) as it's going to be a difficult one to review.

diegohavenstein commented 4 years ago

Awesome! Looking forward to it

Thx