Delphi VCL sample locks up when using "Read using an Event"
Posted: Fri 5. Mar 2021, 17:11
I have just compiled the Delphi VCL sample provided with PCAN-Developer 4 and tried it.
When I select "Read using an Event" on the "Messages" tab, the program locks up after a while.
That's because the VCL thread is waiting in the System.MonitorEnter call in RefreshMessages for access to the FReceivedMessages list which is blocked by the receiving thread. The receiving thread at the same time tries to write a status message which calls (via ProcessStatus -> ShowError -> TextOutput) TThread.Synchronize, which tries to switch to the VCL thread in order to access the VCL. Unfortunately that thread is already blocked while waiting in System.MonitorEnter. -> classical deadlock
My setup is special because it causes a lot "BUSWARNING" messages to be sent, so the deadlock might happen a lot more often than in other settings.
When I select "Read using an Event" on the "Messages" tab, the program locks up after a while.
That's because the VCL thread is waiting in the System.MonitorEnter call in RefreshMessages for access to the FReceivedMessages list which is blocked by the receiving thread. The receiving thread at the same time tries to write a status message which calls (via ProcessStatus -> ShowError -> TextOutput) TThread.Synchronize, which tries to switch to the VCL thread in order to access the VCL. Unfortunately that thread is already blocked while waiting in System.MonitorEnter. -> classical deadlock
My setup is special because it causes a lot "BUSWARNING" messages to be sent, so the deadlock might happen a lot more often than in other settings.