taviso / 123elf

A native port of Lotus 1-2-3 to Linux.
1.17k stars 59 forks source link

Nonblocking read in tight loop #18

Closed bbarenblat closed 2 years ago

bbarenblat commented 2 years ago

123 (built at 2b15de43349174b95c0131f89d52e2532cbebcff) runs one core at 100%. stracing it shows it’s polling stdin for characters:

times({tms_utime=0, tms_stime=0, tms_cutime=0, tms_cstime=0}) = 1721980973
ioctl(0, TCGETS, {c_iflags=0x4003, c_oflags=0x4, c_cflags=0xbf, c_lflags=0xa31, c_line=0, c_cc[VMIN]=0, c_cc[VTIME]=0, c_cc="\x03\x1c\x7f\x15\x04\x00\x00\x00\x11\x13\x1a\x00\x12\x0f\x17\x16\x00\x00\x00"}) = 0
ioctl(0, TCGETS, {c_iflags=0x4003, c_oflags=0x4, c_cflags=0xbf, c_lflags=0xa31, c_line=0, c_cc[VMIN]=0, c_cc[VTIME]=0, c_cc="\x03\x1c\x7f\x15\x04\x00\x00\x00\x11\x13\x1a\x00\x12\x0f\x17\x16\x00\x00\x00"}) = 0
ioctl(0, TCGETS, {c_iflags=0x4003, c_oflags=0x4, c_cflags=0xbf, c_lflags=0xa31, c_line=0, c_cc[VMIN]=0, c_cc[VTIME]=0, c_cc="\x03\x1c\x7f\x15\x04\x00\x00\x00\x11\x13\x1a\x00\x12\x0f\x17\x16\x00\x00\x00"}) = 0
ioctl(0, SNDCTL_TMR_START or TCSETS, {c_iflags=0x4003, c_oflags=0x4, c_cflags=0xbf, c_lflags=0xa31, c_line=0, c_cc[VMIN]=0, c_cc[VTIME]=0, c_cc="\x03\x1c\x7f\x15\x04\x00\x00\x00\x11\x13\x1a\x00\x12\x0f\x17\x16\x00\x00\x00"}) = 0
ioctl(0, TCGETS, {c_iflags=0x4003, c_oflags=0x4, c_cflags=0xbf, c_lflags=0xa31, c_line=0, c_cc[VMIN]=0, c_cc[VTIME]=0, c_cc="\x03\x1c\x7f\x15\x04\x00\x00\x00\x11\x13\x1a\x00\x12\x0f\x17\x16\x00\x00\x00"}) = 0
ioctl(0, TCGETS, {c_iflags=0x4003, c_oflags=0x4, c_cflags=0xbf, c_lflags=0xa31, c_line=0, c_cc[VMIN]=0, c_cc[VTIME]=0, c_cc="\x03\x1c\x7f\x15\x04\x00\x00\x00\x11\x13\x1a\x00\x12\x0f\x17\x16\x00\x00\x00"}) = 0
ioctl(0, TCGETS, {c_iflags=0x4003, c_oflags=0x4, c_cflags=0xbf, c_lflags=0xa31, c_line=0, c_cc[VMIN]=0, c_cc[VTIME]=0, c_cc="\x03\x1c\x7f\x15\x04\x00\x00\x00\x11\x13\x1a\x00\x12\x0f\x17\x16\x00\x00\x00"}) = 0
read(0, "", 1)                          = 0

continually shows up.

I’m using Debian 11 with XTerm 366.

taviso commented 2 years ago

Hmm - you're right, I thought I got this V_TIME/V_MIN logic worked out, but I guess not!

It does want read() to timeout quickly, because it uses expired read()s to run it's event loop - but clearly that is too fast. I think I will try just ignoring the timeout it requests and setting it myself.