SV: SV: [fpc-pascal] writeln in threads on linux
Ole J. Røtne
ole.rotne at online.no
Sun Jul 2 17:12:04 CEST 2006
> Please post the complete code.
Here goes (Typed from my Linux box, as i don't have filesharing going
there):
<---- Start Unit1
Unit unit1;
{$mode objfpc}{$H+}
Interface
Uses
Classes, SysUtils;
Type
threadtest = class(tthread)
constructor Create;
procedure Execute: override;
End;
Var
crit:TRTLCriticalSection;
Implementation
Constructor threadtest.Create;
Begin
FreeOnTerminate := True;
Inherited Create(False);
End;
Procedure threadtest.Execute;
Begin
Repeat
EnterCriticalSection(crit); // Get the same result with/without
WriteLn('Inside Thread');
LeaveCriticalSection(crit); // Get the same result with/without
Until Terminated;
End;
End.
<--- End Unit1
<--- Start Program1
Program Program1
{$mode objfpc}{$H+}
{$DEFINE UseCThreads}
Uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes, SysUtils, Unit1, Keyboard;
Var
MyThread:threadtest;
k:TKeyEvent;
Begin
InitKeyboard;
InitCriticalSection(crit);
MyThread := ThreadTest.Create;
Repeat
k := PollKeyEvent;
EnterCriticalSection(crit); // Get the same result with/without
WriteLn('Main Program');
LeaveCriticalSection(crit); // Get the same result with/without
Until k <> 0;
MyThread.Terminate;
End.
<--- End Program1
Ole JR
More information about the fpc-pascal
mailing list