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

Doing a loop of getchar(1) causesit to hang

Open eyalk5 opened this issue 5 years ago • 1 comments

Hi,

as witnessed in LeaderF, when doing

while(1): 
     let x=getchar(1)
     if !type(nr) && nr == 0:
         continue
     HANDLE input

neovim-qt (with latest neovim server on macos) hangs (from time to time). Especially, it hangs when many keys are sent at once.

That is, it stops handling keys until one cause it to redraw (for example, change the size). This behavior is present in last version of LeaderF . The solution is sleep. It seems to be a thread starvation issue.

eyalk5 avatar Nov 02 '19 15:11 eyalk5

Interesting.

Did a quick test here in vimscript

function! Wat()
	while 1 == 1
		 let x=getchar(1)
		 "if !type(nr) && nr == 0:
		"	 continue
		"HANDLE input
	endwhile
endfunction

I do see a spike in cpu consumption (in nvim) but no thread variation in either nvim or nvim-qt. The UI blocks with the cursor on the corner and no rendering happens even with a resize.

Using getchar() avoids the cpu comsumption but still blocks rendering (not surprising).

I thought this was supposed to work (https://github.com/neovim/neovim/pull/5384) but maybe I was wrong.

PS: funny bit - this also happens with vim-gtk.

equalsraf avatar Nov 04 '19 21:11 equalsraf