Comment by groundzeros2015
1 month ago
The answer is you wrap it and you don’t return until the thing stored in the thread local is not needed
1 month ago
The answer is you wrap it and you don’t return until the thing stored in the thread local is not needed
So we can't return the closure?
Then it's clearly only half a solution.
The example I gave above should work fine in any language with first-class closures.
> The closure problem can be neatly described by as “how do I get extra data to use within this qsort call?”
you also need to restore the _qsort2_closure when done. But again you are reinventing dynamic scoping with all its advantages and disadvantages.
1 reply →
This is the classic lexical vs dynamic scoping. Dynamic scoping works great until it doesn't.
Don’t use C then? It sounds like you want JavaScript, Python, or Lisp.
Once again, the caller of the API does not declare any variables so there is no dynamic scoping.