neovim-qt icon indicating copy to clipboard operation
neovim-qt copied to clipboard

Prove Thread Safety of GuiNewWindow

Open jgehrig opened this issue 2 years ago • 1 comments

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.

jgehrig avatar Jul 27 '21 02:07 jgehrig

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

  1. as part of a signal onWindowDestroyed
  2. inside createWindow()
  3. 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.

equalsraf avatar Feb 02 '22 22:02 equalsraf