Remix.run Logo
groundzeros2015 6 hours ago

Thread locals do solve the problem. You create a wrapper around the original function. You set a global thread local user data, you pass in a function which calls the function pointer accepting the user data with the global one.

srcreigh 4 hours ago | parent | next [-]

Yep. Thread locals are probably faster than the other solutions shown too.

It’s confusing to me that thread locals are “not the best idea outside small snippets” meanwhile the top solution is templating on recursion depth with a constexpr limit of 11.

groundzeros2015 an hour ago | parent [-]

The method of having static variables to store state in functions is used heavily in ANSI C book. It’s honestly a beautiful technique when used prudently.

gpderetta 3 hours ago | parent | prev [-]

reentrancy.

groundzeros2015 an hour ago | parent [-]

It doesn’t store state for later. It’s literally impossible to tell it’s happening.