Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2006-07

Re: writeln in threads on linux

3 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Antal
Show quoted text 7 lines
Can anyone explain why i get output like this in a small test program: Inside Thread Main Loop Inside Thread Main Loop Inside Thread Main Loop

That's because the line terminator!
#10#13 or #13#10 acts differently
So, check in the source code which one is used, because the first one is not suitable in Windows!
As you supposedly know, the end line terminator is different on Mac, Unix and Windows.
Mac only uses #13
Unix only uses #10
Windows uses #13#10 (CRLF)
This comes from the fact that telex machines needed to complete two different actions in order to start writing in a new line (just like what you have to do on a normal typewriter): first to step on the next row, then to put the head at the beginning of the row.
So, basically #10 means Line-Feed (LF) (step to the next row) While #13 means Carriage Return (CR) which means "move the carriage -the printing head- to the beginning of the row) - or what you are doing on a typewriter by hand, using that lever from the right upper part of the machine.
so, when OS-es split up, the kept what they wanted, although MS had had to preserve the standard as long as they was part of IBM those times, and IBM telex machines needed the time of two caracter printing to complete a CRLF operation.
But I I've seen, sometimes in FP source codes the CRLF is using as LFCR which does nothing wrong on Unix, as long as CR is invisible, but on

So just look out for this in the source-code.
Or just use
write('Main Loop',#13#10);
:^)

Show quoted text 36 lines
On Windows the output are lined up just as I would expect: Inside Thread Main Loop Inside Thread Main Loop Here's a snip of the code: // Main Prog Thr := threadtest.Create; Repeat k := PollKeyEvent; WriteLn('Mein Loop'); Sleep(100); Until k 0; And the ThreadTest.Execute i just: Procedure ThreadTest.Execute; Begin Repeat WriteLn('Inside Thread'); Sleep(100); Until Terminated End; And if this is a "wrong way" of doing this thing, could someone tell me how it should be.. Oh and BTW. Using FPC 2.1.1 snapshot from 14.06.06 (from Lazarus site), on OpenSuSe 10.1..

Reply by email

Ole J. Røtne
to Antal
Show quoted text 17 lines
> Can anyone explain why i get output like this in a small test program: > Inside Thread > Main Loop > Inside Thread > Main Loop > Inside Thread > Main Loop That's because the line terminator! #10#13 or #13#10 acts differently So, check in the source code which one is used, because the first one is not suitable in Windows! As you supposedly know, the end line terminator is different on Mac, Unix and Windows. Mac only uses #13 Unix only uses #10 Windows uses #13#10 (CRLF)

This I do know :)

So just look out for this in the source-code. Or just use write('Main Loop',#13#10); :^)

If I do this I get this instead:
Inside Thread

Main Loop

Inside Thread

Main Loop

Inside Thread

Main Loop

And one more thing.

When the program terminates, my terminal don't work any more either.. So somethings not right someplace..

Another sidenote is that when I don't use threads, the output is as expected..:

Main Loop
Main Loop
Main Loop
Main Loop

Ole JR

Reply by email