neovim-qt
neovim-qt copied to clipboard
Prove Thread Safety of GuiNewWindow
Can s_windows
or s_lastActiveWindow
be accessed from multiple threads?
If yes, the code as written is unsafe... Please prove that the code is thread safe, or add a mutex.
Example)
Create Window 1
Create Window 2
Simultaneous:
onWindowDestroyed (Window 1)
onWindowDestroyed (Window 2)
Nothing guards against concurrent access of s_windows (or any of the other global statics). We could have undefined behavior...
Perhaps something about the way Qt is implemented makes this safe? If we think this is safe, we should add a comment about why this is safe to the code. It is not immediately obvious.
I'm a bit out of the loop here. In what situation would s_windows be accessed from another thread? The only places I see it in use are
- as part of a signal onWindowDestroyed
- inside createWindow()
- App::event
I think all these are carried out in the main thread.
Now if this were to be used from another thread, that would be a problem.