FileClose in thread influences message loop in main program
Original Reporter info from Mantis: Hansi
-
Reporter name: Hansi
Original Reporter info from Mantis: Hansi
- Reporter name: Hansi
Description:
A program (TApplication + TForm) with a second thread (TThread). If the thread closes a file descriptor which is not open, the message loop of the main thread forgets to wait for new events but executes rapidly. New events are processed, but there is no waiting any more.
The attached test program demonstrates the problem. Compile with -dUseCThreads. Then run it. The main thread registes the OnIdle handler, which is usually only called once after every handled event. If the window has no focus and no mouse pointer crosses the window, OnIdle is not executed.
The thread executes FileClose once a second with a non-existent file handle (and if it existed, it will be closed after the first iteration). After 2 seconds move the mouse across the window several times, then leave it again. The OnIdle calls still occur without pause (but should not). If there was no Sleep(), the CPU usage is 100%.
After investigation this with strace, the close() calls result in an EBADF error. I tried to get the same error with write() to a non-opened file, but this did not produce the problem.
Only tested with GTK1 on a Linux machine (Debian Sid).
Mantis conversion info:
- Mantis ID: 12009
- Version: 0.9.24
- Monitored by: » Hansi (Hansi)