[fpc-pascal] Where is IsMultiThreaded set under Linux?

Graeme Geldenhuys graemeg.lists at gmail.com
Fri Oct 8 14:03:12 CEST 2010


Hi,

On 8 October 2010 13:37, Sven Barth wrote:
>
> Note: You must start at least one thread (besides the main thread) to turn
> "IsMultiThread" to true.

I am, and changing my fpGUI code to the following does indeed prove
that you are right. As soon as my thread is started, I see the '*****'
output, but unfortunately only once. Let me explain.

   if IsMultiThreaded then
       begin
         writeln('******');
        CheckSynchronized();
       end;


What I am trying to debug is that as soon as I call mythread.waitfor,
then WaitFor() blocks the applications main event loop, thus the
application just hangs. This only occurs under X11, not under Windows.

I can work around that problem, by doing the following.... I have to
introduce a boolean variable in my thread class, set it to True at the
end of the thread's Execute method, as follows:

procedure TBarThread.Execute;
begin
  FFinished := False;    // work-around variable
  while not Terminated do
  begin
    Synchronize(@UpdateProgressBar);
  end;
  FFinished := True;     // work-around variable
end;

....Then use a while loop (instead of WaitFor), to check for that
variable, and if not True, call fpgApplication.ProcessMessages
instead.

procedure TMainForm.ButtonClicked(Sender: TObject);
begin
  ProgressBar1.Position := ProgressBar1.Min;
  if not Assigned(FThread) then
  begin
    writeln('program: creating thread...');
    FThread := TBarThread.Create(True);
    FThread.ProgressBar := ProgressBar1;
  end;
  writeln('program: starting the thread...');
  FThread.Start;

  writeln('program: waiting for thread...');
  FThread.WaitFor;    // Can use this, it blocks the main event loop

  // my work-around
  while not FThread.Finished do
  begin
    sleep(100);
    fpgApplication.ProcessMessages;
  end;

  writeln('program:  thread is finished!');
  Label1.Text := 'Thread is done';
  FreeAndNil(FThread);
end;



Obviously this is a hack, and damn ugly. I shouldn't need to do this.
But still I haven't figured out why the application's main  event loop
is blocked by WaitFor.

Writing a console app, that does use a thread to count down from 20 to
0,  I can use a WaitFor, and it works (even under Linux). So clearly
there is a problem in fpGUI, and more specifically in the X11 support
code. Unbelievable that I haven't picked up on this sooner.... then
again, I have never had a need for WaitFor usage until now.  :-/


-- 
Regards,
  - Graeme -


_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net:8080/fpgui/



More information about the fpc-pascal mailing list