Conversation
Signed-off-by: ivanpauno <ivanpauno@ekumenlabs.com>
| #ifndef _WIN32 | ||
| # define THREAD_LOCAL_STORAGE __thread | ||
| #else | ||
| # define THREAD_LOCAL_STORAGE __declspec(thread) |
There was a problem hiding this comment.
rcutils/include/rcutils/macros.h
Line 33 in e52f2cf
There was a problem hiding this comment.
It's the windows specific way of declaring a variable thread local. See https://docs.microsoft.com/en-us/cpp/cpp/thread?view=vs-2019.
There was a problem hiding this comment.
Oh, I see we already had this
| #ifdef _WIN32 | ||
| # define WINDOWS_ENV_BUFFER_SIZE 2048 | ||
| static char __env_buffer[WINDOWS_ENV_BUFFER_SIZE]; | ||
| THREAD_LOCAL_STORAGE static char __env_buffer[WINDOWS_ENV_BUFFER_SIZE]; |
There was a problem hiding this comment.
This may cause memory allocations where before they did not occur, see:
rcutils/include/rcutils/error_handling.h
Lines 101 to 141 in e70143a
hidmic
left a comment
There was a problem hiding this comment.
Hmm, the fix itself is a fair solution, but I'm curious about rcutils_get_env. It wraps getenv_s when compiled for Windows and getenv for all the other platforms. But then, getenv_s ought to be available in all platforms as it is included in the C11 standard. Why not simply use getenv_s where appropriate?
|
Also, neither is thread-safe as far as I know:
https://en.cppreference.com/w/c/program/getenv I'd recommend reading all of #30 if you haven't already. |
|
Alright, I see now. And I think the existing one is the best solution. In light of this, should #30 be closed as |
I'm not sure. I think it's definitely not needed now, but maybe others have an opinion about it. We could close it or leave it open, doesn't matter to me. If we close it we can always reopen it. |
|
I think in light of what we discussed in ros2/rclcpp#987 (comment) , we should close this out in favor of a new PR. I'm going to go ahead and do that, but feel free to re-open if you disagree. |
Complements ros2/rcl#502
Documentation about thread local storage: