Tanzinul Islam b86bf840d1 Count threads after thread-creation while still holding mutex lock
The `Mutex` is locked with the `MutexLock` before spawning the thread, so that the thread is prevented from completing (by being blocked on `Mutex`) before the new thread count is obtained. However, the existing bug (introduced in 22e6055) releases `Mutex` before obtaining the new thread count, which allows the thread to run to completion in the meantime.

Also, since the `(thread_count_after_create != starting_count + 1)` condition (line 328) skips the remainder of the `for`-loop body on every iteration, `thread_count_after_join` stays uninitialized.

I believe this is why [this test failed][1] on the macOS CI with this trace:

```
[----------] 1 test from GetThreadCountTest
[ RUN      ] GetThreadCountTest.ReturnsCorrectValue
googletest/test/googletest-port-test.cc:350: Failure
Expected equality of these values:
  thread_count_after_create
    Which is: 1
  starting_count + 1
    Which is: 2

googletest/test/googletest-port-test.cc:351: Failure
Expected equality of these values:
  thread_count_after_join
    Which is: 140493185949400
  starting_count
    Which is: 1

[  FAILED  ] GetThreadCountTest.ReturnsCorrectValue (2 ms)
[----------] 1 test from GetThreadCountTest (2 ms total)
```

[1]: https://github.com/google/googletest/actions/runs/6064919420/job/16453860690?pr=3049
2023-09-03 16:46:02 +01:00
..
BUILD.bazel Add googletest-message-test to the Bazel tests 2023-08-02 07:40:55 -07:00
googletest-break-on-failure-unittest_.cc Use "#ifdef GTEST_OS_..." instead of "#if GTEST_OS_..." 2023-03-06 07:14:21 -08:00
googletest-break-on-failure-unittest.py Fix Python docstrings to match style guide 2023-01-26 09:04:40 -08:00
googletest-catch-exceptions-test_.cc Running clang-format over all of GoogleTest 2022-03-15 13:42:11 -07:00
googletest-catch-exceptions-test.py Merge pull request #4300 from eltociear:patch-1 2023-06-26 17:24:42 -07:00
googletest-color-test_.cc Running clang-format over all of GoogleTest 2022-03-15 13:42:11 -07:00
googletest-color-test.py Fix formatting in subset of Python files 2023-01-25 09:14:26 -08:00
googletest-death-test_ex_test.cc Use "#ifdef" with public macros 2023-03-06 07:15:44 -08:00
googletest-death-test-test.cc Add missing std includes 2023-04-20 14:29:09 -07:00
googletest-env-var-test_.cc Running clang-format over all of GoogleTest 2022-03-15 13:42:11 -07:00
googletest-env-var-test.py Fix formatting in subset of Python files 2023-01-25 09:14:26 -08:00
googletest-failfast-unittest_.cc Running clang-format over all of GoogleTest 2022-03-15 13:42:11 -07:00
googletest-failfast-unittest.py Fix formatting in subset of Python files 2023-01-25 09:14:26 -08:00
googletest-filepath-test.cc Fix spelling 2023-04-25 20:20:01 +02:00
googletest-filter-unittest_.cc Running clang-format over all of GoogleTest 2022-03-15 13:42:11 -07:00
googletest-filter-unittest.py Fix formatting in subset of Python files 2023-01-25 09:14:26 -08:00
googletest-global-environment-unittest_.cc Googletest export 2021-02-18 13:27:15 -05:00
googletest-global-environment-unittest.py Fix formatting in subset of Python files 2023-01-25 09:14:26 -08:00
googletest-json-outfiles-test.py Add missing std includes 2023-04-20 11:01:56 -07:00
googletest-json-output-unittest.py Add missing std includes 2023-04-20 11:01:56 -07:00
googletest-list-tests-unittest_.cc Add missing std includes 2023-04-20 14:29:09 -07:00
googletest-list-tests-unittest.py Fix Python docstrings to match style guide 2023-01-26 09:04:40 -08:00
googletest-listener-test.cc Add missing std includes 2023-04-20 14:29:09 -07:00
googletest-message-test.cc Make testing::Message support streamed AbslStringify values 2023-08-01 14:01:41 -07:00
googletest-options-test.cc Use "#ifdef GTEST_OS_..." instead of "#if GTEST_OS_..." 2023-03-06 07:14:21 -08:00
googletest-output-test_.cc Skip entire test suite with GTEST_SKIP() in SetUpTestSuite 2023-06-14 06:41:11 -07:00
googletest-output-test-golden-lin.txt Skip entire test suite with GTEST_SKIP() in SetUpTestSuite 2023-06-14 06:41:11 -07:00
googletest-output-test.py gtest.cc: add a newline after a failure when there is no OS stack trace. 2023-03-22 20:19:44 -07:00
googletest-param-test2-test.cc Running clang-format over all of GoogleTest 2022-03-15 13:42:11 -07:00
googletest-param-test-invalid-name1-test_.cc Running clang-format over all of GoogleTest 2022-03-15 13:42:11 -07:00
googletest-param-test-invalid-name1-test.py Fix formatting in subset of Python files 2023-01-25 09:14:26 -08:00
googletest-param-test-invalid-name2-test_.cc Add missing std includes 2023-04-20 14:29:09 -07:00
googletest-param-test-invalid-name2-test.py Fix formatting in subset of Python files 2023-01-25 09:14:26 -08:00
googletest-param-test-test.cc Apply clang-tidy fixes 2023-03-07 22:33:56 -08:00
googletest-param-test-test.h Running clang-format over all of GoogleTest 2022-03-15 13:42:11 -07:00
googletest-port-test.cc Count threads after thread-creation while still holding mutex lock 2023-09-03 16:46:02 +01:00
googletest-printers-test.cc googletest: Add universal printer for std::span 2023-08-25 07:46:02 -07:00
googletest-setuptestsuite-test_.cc Running clang-format over all of GoogleTest 2022-03-15 13:42:11 -07:00
googletest-setuptestsuite-test.py Fix formatting in subset of Python files 2023-01-25 09:14:26 -08:00
googletest-shuffle-test_.cc Apply clang-tidy fixes 2023-03-07 22:33:56 -08:00
googletest-shuffle-test.py Fix formatting in Python files 2023-01-26 11:06:14 -08:00
googletest-test-part-test.cc Running clang-format over all of GoogleTest 2022-03-15 13:42:11 -07:00
googletest-throw-on-failure-test_.cc Running clang-format over all of GoogleTest 2022-03-15 13:42:11 -07:00
googletest-throw-on-failure-test.py Fix Python docstrings to match style guide 2023-01-26 09:04:40 -08:00
googletest-uninitialized-test_.cc Running clang-format over all of GoogleTest 2022-03-15 13:42:11 -07:00
googletest-uninitialized-test.py Fix formatting in subset of Python files 2023-01-25 09:14:26 -08:00
gtest_all_test.cc Googletest export 2018-10-29 13:46:16 -04:00
gtest_assert_by_exception_test.cc Running clang-format over all of GoogleTest 2022-03-15 13:42:11 -07:00
gtest_dirs_test.cc Remove some filesystem APIs and tests under !GTEST_HAS_FILE_SYSTEM 2023-02-14 08:33:42 -08:00
gtest_environment_test.cc Running clang-format over all of GoogleTest 2022-03-15 13:42:11 -07:00
gtest_help_test_.cc Use "#ifdef" with public macros 2023-03-06 07:15:44 -08:00
gtest_help_test.py Merge pull request #4333 from ngie-eign:gtest_help_test-fix-FreeBSD 2023-08-15 11:39:35 -07:00
gtest_json_test_utils.py Fix formatting in subset of Python files 2023-01-25 09:14:26 -08:00
gtest_list_output_unittest_.cc Googletest export 2021-02-05 10:39:30 -08:00
gtest_list_output_unittest.py Fix formatting in subset of Python files 2023-01-25 09:14:26 -08:00
gtest_main_unittest.cc Running clang-format over all of GoogleTest 2022-03-15 13:42:11 -07:00
gtest_no_test_unittest.cc Comments changes, no functionality changes 2018-08-14 14:04:07 -04:00
gtest_pred_impl_unittest.cc IWYU: Add missing std includes 2023-01-05 08:44:01 -08:00
gtest_premature_exit_test.cc Running clang-format over all of GoogleTest 2022-03-15 13:42:11 -07:00
gtest_prod_test.cc Comments changes, no functionality changes 2018-08-14 14:04:07 -04:00
gtest_repeat_test.cc Use '=default' to define trivial constructor/destructors 2023-04-21 10:41:25 -07:00
gtest_skip_check_output_test.py Fix formatting in subset of Python files 2023-01-25 09:14:26 -08:00
gtest_skip_environment_check_output_test.py Fix formatting in subset of Python files 2023-01-25 09:14:26 -08:00
gtest_skip_in_environment_setup_test.cc Running clang-format over all of GoogleTest 2022-03-15 13:42:11 -07:00
gtest_skip_test.cc Running clang-format over all of GoogleTest 2022-03-15 13:42:11 -07:00
gtest_sole_header_test.cc Running clang-format over all of GoogleTest 2022-03-15 13:42:11 -07:00
gtest_stress_test.cc Add missing std includes 2023-04-20 14:29:09 -07:00
gtest_test_macro_stack_footprint_test.cc Running clang-format over all of GoogleTest 2022-03-15 13:42:11 -07:00
gtest_test_utils.py Fix formatting in Python files 2023-01-26 11:06:14 -08:00
gtest_testbridge_test_.cc Running clang-format over all of GoogleTest 2022-03-15 13:42:11 -07:00
gtest_testbridge_test.py Replace deprecated python calls 2023-01-17 12:16:29 -08:00
gtest_throw_on_failure_ex_test.cc Running clang-format over all of GoogleTest 2022-03-15 13:42:11 -07:00
gtest_unittest.cc Merge pull request #4323 from pgawro:gtest_ExpectThrowTest_DoesNotGenerateUnreachableCodeWarning 2023-08-03 08:32:42 -07:00
gtest_xml_outfile1_test_.cc Googletest export 2018-12-03 12:54:11 -05:00
gtest_xml_outfile2_test_.cc Add missing std includes 2023-04-20 11:01:56 -07:00
gtest_xml_outfiles_test.py Add missing std includes 2023-04-20 11:01:56 -07:00
gtest_xml_output_unittest_.cc Add missing std includes 2023-04-20 11:01:56 -07:00
gtest_xml_output_unittest.py Add missing std includes 2023-04-20 11:01:56 -07:00
gtest_xml_test_utils.py Fix spelling 2023-04-25 20:20:01 +02:00
gtest-typed-test2_test.cc Running clang-format over all of GoogleTest 2022-03-15 13:42:11 -07:00
gtest-typed-test_test.cc Remove unneccessary "#if _MSC_VER" 2023-02-02 09:02:17 -08:00
gtest-typed-test_test.h Running clang-format over all of GoogleTest 2022-03-15 13:42:11 -07:00
gtest-unittest-api_test.cc cleanup from unique_ptr branch 2022-07-01 15:33:13 -07:00
production.cc Comments changes, no functionality changes 2018-08-14 14:04:07 -04:00
production.h Running clang-format over all of GoogleTest 2022-03-15 13:42:11 -07:00