Multiple (near-)simultaneous calls to TThread.Synchronize causing program to hang
Original Reporter info from Mantis: ahydra
-
Reporter name: Colin Haywood
Original Reporter info from Mantis: ahydra
- Reporter name: Colin Haywood
Description:
See the attached code (from my post at http://community.freepascal.org:10000/bboards/message?message_id=334220&forum_id=24092), for which the equivalent Delphi version works correctly for any (sensible) value of MAXTHREADS. However under FP the program only works for MAXTHREADS = 1, and hangs for MAXTHREADS > 1.
The Delphi implementation of TThread.Synchronize (for Delphi 7, classes.pas line 9556) is much more sophisticated than that of FP (for 0.9.26.2 beta, classes.inc line 123), as it keeps a list of the procedures that need to be called (the parameter passed to Synchronize(...)) and uses Windows threadsafe API calls to organise this list. However the FP one appears to just overwrite the details of any previous call, whether or not it has been executed, and this I believe to be the cause of this problem.
Steps to reproduce:
See code attached. When the button is clicked, the program should display the 'Total =' message box with a number. However with MAXTHREADS > 1 the program will hang instead.
Additional information:
Sometimes Lazarus stops responding to program reset (CTRL-F2) commands once the program has hung.
Mantis conversion info:
- Mantis ID: 14431
- OS: Windows
- OS Build: XP
- Platform: x86
- Version: 2.2.2
- Fixed in version: 3.0.0
- Fixed in revision: 23227 (#764f36a1)