Skip to content

Conversation

@zouyonghao
Copy link
Contributor

@zouyonghao zouyonghao commented Apr 22, 2021

Reason for the change

for #6956

Description

use unique_ptr to deallocate the object

Checklist

// }
// return TLS_get_rng();

static thread_local std::unique_ptr<rng_t> tls_rng(new rng_t());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well. That looks great. I'll check that this works on the oldest platforms we support, and if it does, we'll merge this and backport it to v2.4.x.

Thanks for the PR.

@srh
Copy link
Contributor

srh commented Feb 20, 2022

Thank you again for the PR.

I am closing in favor of #7010, which merges your change, and another, to v2.4.x. We are not going to be using the next branch in the future, so this PR does not need to be merged to next.

If you are interested, see the changes in the second commit of #7010. We need NOINLINE to stop the compiler from optimizing access to thread local storage in this circumstance:

auto x = TLS_get_foo();
on_thread_t th(other);
auto y = TLS_get_foo();

The compiler (or link time optimizer) does not know that on_thread_t th(other) will switch the coroutine to a different POSIX thread. Thus it may assume that both calls to TLS_get_foo(), after inlining, both access a thread_local, which on_thread_t's constructor does not modify, thus they return the same value. Using NOINLINE, we prevent this optimization.

@srh srh closed this Feb 20, 2022
@srh
Copy link
Contributor

srh commented Feb 20, 2022

I'll add, because thread_local is a C++11 feature, I've decided to not worry about platforms which do not support it (which might be CentOS 6 with an old system gcc 4.8 compiler).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants