test: Make g_insecure_rand_ctx thread_local #14953

pull MarcoFalke wants to merge 1 commits into bitcoin:master from MarcoFalke:Mf1812-testThreadLocal changing 3 files +21 −23
  1. MarcoFalke commented at 7:35 pm on December 13, 2018: member

    Some tests might spin up several threads and FastRandomContext is not thread safe.

    Fix that by giving each thread their own randomness context (as opposed to e.g. making FastRandomContext thread safe or add locks elsewhere).

    Also, add the g_ prefix to it (according to developer notes), since I am touching it anyway.

  2. test: Make g_insecure_rand_ctx thread_local faead93c6c
  3. sipa commented at 7:36 pm on December 13, 2018: member

    This seems overkill, as most tests are single-threaded. The multi-threaded test could just have one RNG per thread?

    By that I mean having an explicit “FastRandomContext rng(true);” in each of the threads.

  4. MarcoFalke commented at 7:54 pm on December 13, 2018: member
    The alternative you suggest (only give each thread their own randomness context when they are multithreaded) would involve (re)writing the InsecureRandRange helpers. I’d prefer to just add the thread_local keyword unless there are observable performance regressions.
  5. MarcoFalke added the label Tests on Dec 13, 2018
  6. sipa commented at 7:55 pm on December 13, 2018: member
    Oh, I forgot about the wrappers for the global test RNG. Objection withdrawn.
  7. gmaxwell commented at 9:18 pm on December 13, 2018: contributor
    utACK
  8. DrahtBot commented at 9:39 pm on December 13, 2018: member

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #14464 (refactor: make checkqueue manage the threads by itself (also removed some boost dependencies) by ken2812221)
    • #14193 (validation: Add missing mempool locks by MarcoFalke)
    • #13804 (WIP: Transaction Pool Layer by MarcoFalke)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  9. MarcoFalke referenced this in commit a5aea9654f on Dec 13, 2018
  10. MarcoFalke merged this on Dec 13, 2018
  11. MarcoFalke closed this on Dec 13, 2018

  12. MarcoFalke deleted the branch on Dec 13, 2018
  13. laanwj commented at 7:28 am on December 15, 2018: member

    No idea if this is significant, but mentioning just in case:

    Thread-local support used to be optional before this (was only used in sync.h in debug mode optionally). This change ignores HAVE_THREAD_LOCAL and makes it mandatory.

  14. Sjors commented at 10:37 am on December 15, 2018: member

    Should those tests perhaps fail explicitly, like in sync.cpp?

    0#if !defined(HAVE_THREAD_LOCAL)
    1static_assert(false, "thread_local is not supported");
    2#endif
    

    Or should we make it mandatory in ./configure?

    Some earlier related discussion:

    We bumped the requirement from g++ 4.7 to g++ 4.8 in #11755 @theuni wrote there:

    thread_local was also off-limits due to missing support in osx’s clang. It’s been added as of XCode 8 on September 13, 2016. I’m uneasy with that as a minimum requirement.

    From Apple docs: “Xcode 8.1 requires a Mac running macOS 10.11.5 or later”. We still support macOS 10.10. We could consider bumping that to 10.11.5, or accept that some tests won’t run.

    Additionally, last time I checked this, the use of thread_local causes new symbols to be pulled in from glibc on Linux, meaning that we would lose back-compat with older versions. I’d have to re-test to see where the break lies.

    So perhaps this depends on if we drop e.g. Ubuntu Trusty 14.04 in the next release.

  15. MarcoFalke commented at 5:52 pm on December 16, 2018: member
    thread_local was added in C++11, which we require right now and we are about to switch to C++14 soon, so a compiler not supporting it shouldn’t be a problem.
  16. sipa commented at 6:42 pm on December 16, 2018: member

    @MarcoFalke That reasoning seems backwards. We identify what C++ version (and features) we can use based on the platforms we want to support. I don’t mean to say that this particular change is a problem, but just because we’re considering C++14 does not mean we should drop support for every platform that doesn’t support every feature from C++11 or C++14.

    Does this mean we have now removed support for OSX 10.10 for the unit tests with this change?

  17. MarcoFalke commented at 0:50 am on December 17, 2018: member
    It would be easier to decide which C++11 (or C++14) features are acceptable to use when there was a guideline/process that defines compatibility requirements we want to achieve.
  18. Sjors commented at 2:54 pm on December 17, 2018: member

    We identify what C++ version (and features) we can use based on the platforms we want to support.

    It’s probably a bit of both. It’s easier to support older platforms if it only causes minor inconveniences.

    This change indeed breaks macOS 10.10 support for the unit tests. Afaik it takes a patch with an ifdef to restore support for the majority of tests. @jonasschnelli might be able to confirm since he has VMs with older macOS versions.

  19. MarcoFalke referenced this in commit d4197812d4 on Dec 18, 2018
  20. LarryRuane referenced this in commit 10173c3f3b on Apr 29, 2021
  21. LarryRuane referenced this in commit b19418218a on Jun 1, 2021
  22. pravblockc referenced this in commit a753b89010 on Aug 2, 2021
  23. pravblockc referenced this in commit 5faf600399 on Aug 3, 2021
  24. Munkybooty referenced this in commit 4d5ae893ed on Aug 8, 2021
  25. Munkybooty referenced this in commit 2c534af879 on Aug 8, 2021
  26. Munkybooty referenced this in commit ac674a7daf on Aug 11, 2021
  27. Munkybooty referenced this in commit f26f5dee35 on Aug 11, 2021
  28. Munkybooty referenced this in commit 4a4ee90ad9 on Aug 13, 2021
  29. Munkybooty referenced this in commit 744813b454 on Aug 15, 2021
  30. MarcoFalke locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-10-06 16:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me