Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

reentrancy.




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

Imagine a comparison function that needs to call sort() as part of its implementation. You could argue that's probably a bad idea, but it would be a problem for this case.

(You could solve that with a manually maintained stack for the context in a thread local, but you'd have to do that case-by-case)


That is true. It can be protected against with assert.

I think the times you need to do this are few. And this version is much more pruden.


Assert what, exactly?

Anyway, the larger point is that a re-entrant general solution is desirable. The sort example might be a bit misguided, because who calls sort-inside-sort[0]? Nobody, realistically, but these types of issues are prevalent in the "how to do closures" area... and In C every API does it slightly differently, even if they're even aware of the issues.

[0] Because there's no community that likes nitpicking like the C (or C++) community. I considered preempting that objection :). C++ has solved this, so there's that.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: