Hello lazarus-list,
I'm working in a program that needs multiple threads and one will
synchronize with main thread to display a log. I do not wish to
continue the caller thread meanwhile the Synchronize has not been
finished, so I had added a set of events to handle this. My program
locks up just after start, and the offended method is in the
Synchronize feature. So I start to rewrite the same idea around the
multithread example code keeping only the things that I need, and to
ask to you if this is a Synchronize bug/problem or a non-wanted
programming technique, and I must replace the code with a different
approach (if possible).
The main problem is here, in the execute method:
-----------------------------------------
procedure TMyThread.Execute;
begin
fStatusText := 'TMyThread Starting...';
Synchronize(@Showstatus);
fStatusText := 'TMyThread Running...';
while (not Terminated) and (true {any condition required}) do begin
m_Event.WaitFor(1000); //It should be INFINITE...
m_Event.ResetEvent;
if NewStatus <> fStatusText then begin
m_Lock.Enter;
fStatusText := newStatus;
Synchronize(@Showstatus);
m_Lock.Leave;
end;
m_EventDone.SetEvent;
end;
end;
-----------------------------------------
The idea is to modify "NewStatus" from an outside procedure
(CriticalSection protected) and activate m_Event to let the Execute
know that it must launch the syncronize, then it will wait for
"m_EventDone" to be signaled before continue.
Attached is the Multithread example mainunit.pas modified with my
changes to raise the bug/problem, simply replace the example file with
this one.
System: WinXP SP2
Lazarus: 0.9.24 and 0.9.25 #13510 (packages from the web)
FPC: As shipped with lazarus 2.2.0 and 2.2.1
CPU: Pentium Hyperthreading (tested without hyper too).
--
Best regards,
JoshyFun
_______________________________________________
Lazarus mailing list
[email protected]
http://www.lazarus.freepascal.org/mailman/listinfo/lazarus