On Thu, Aug 10 2023, Robert Pluim wrote: > Hmm. Maybe putting it in `deactivate_process' is better (not that Iʼve > tested 😺) After a night of sleep, it occurred to me that this could also be considered a problem of incomplete initialization of the fd_callback_info[fd] struct. So I wondered who is supposed to initialize it. Unfortunately, there is half a dozen of add__fd functions that set various bits, some call each other, some duplicate code. None of them sets the waiting_thread slot. And there is no single point that clears everything out (except init_process_emacs). I also discovered that recompute_max_desc considers an fd unused if the .flags field is zero. Luckily, recompute_max_desc is only called in three places: delete_write_fd, delete_keyboard_wait_descriptor and deactivate_process. The call in deactivate_process seems redundant as it calls the other two anyway. It seems easier to re-initialize the struct when it becomes unused than to initialize it when it is used the first time. So I'm proposing the patch below that moves the re-initialization to one single place, namely: recompute_max_desc. Helmut