I'm writing my own GLFW class wrapper and stumbled upon function reentrancy question.
GLFW documentation states that some functions are not reentrant (glfwCreateWindow
, etc.) and "must not be called from any callback function".
Now consider the following code:
int main() {
try {
vkc::glfwWrapper a, b;
a.createWindow(640, 520, "a");
a.onClose = [&b](auto self) {
b.createWindow(640, 520, "b");
};
b.onClose = [&a](auto self) {
a.createWindow(640, 520, "a");
};
vkc::glfwWrapper::waitEvents();
}
catch (std::exception& e) {
/* do stuff */
}
return 0;
}
onClose
is a std::function
thingy and is called on close callback. glfwCreateWindow
will not be called with the GLFWwindow
that belongs to callback. But what about GLFWwindow
that does not belong to callback?
Wikipedia states that, "In computing, a computer program or subroutine is called reentrant if it can be interrupted in the middle of its execution, and then be safely called again ("re-entered") before its previous invocations complete execution." Technically that means it should be safe to do as I did, because I'm not interrupting anything, however that "any" really misleads me.
Aucun commentaire:
Enregistrer un commentaire