[fpc-pascal] Writeln() behaves differently on Windows and Linux, why?

Tomas Hajny XHajT03 at hajny.biz
Fri Jul 10 01:26:24 CEST 2020


On 2020-07-10 01:05, Travis Siegel wrote:
> On 7/9/2020 5:11 PM, Tomas Hajny wrote:
>> On 2020-07-09 22:58, Michael Van Canneyt wrote:
>>> On Thu, 9 Jul 2020, Bo Berglund via fpc-pascal wrote:
>>> 
>>>> On Thu, 9 Jul 2020 19:36:31 +0200 (CEST), Michael Van Canneyt
>>>> <michael at freepascal.org> wrote:
>>>> 
>>>>> Is this done in a thread ? Since you're using indy, I suppose so.
>>>>> 
>>>>> The crt unit is not thread safe. The implementation on Windows and 
>>>>> Linux is
>>>>> totally different, which may explain the difference you see.
>>>> 
>>>> Is there a way to check user keyboard input in the main program 
>>>> while
>>>> action is being done in the server's threads?
>>> 
>>> Sure, do a fpselect() on file descriptor 0.
>> 
>> You can use the unit Keyboard as well, which is cross-platform.
>> 
> cross platform doesn't mean thread safe, which is the primary reason
> for *not* using crt unit.  I have no idea if keyboard is thread safe
> or not, and I've not seen anything in this discussion to answer that
> question either.

The point is that unit Keyboard makes no changes to the console output 
(unlike unit Crt). Unit Crt provides special features allowing to 
perform output at a particular position of the console (which makes it 
less reliable in multi-threaded scenarios). Without this unit, standard 
simple I/O is used. No, it isn't guaranteed to be thread-safe per se, 
you should make sure to wait for finishing output from the first thread 
before you start writing in another, that's your responsibility, but 
there are ways for achieving that (as mentioned earlier in this thread).


> Is there sample code of server code so testing can be performed
> outside the discussion parameters? I have looked for years for
> client/server information for freepascal, and never found anything,
> then this discussion shows some code for running a server, where did
> that information come from? I'm apparently really bad on searching for
> said information.

I'm not sure how we got from a multi-threaded application to 
client/server, but there are certainly examples of using FPC for both 
client and server in our SVN (see e.g. packages/fcl-net/examples/ and 
packages/fcl-web/examples/).

Toams


More information about the fpc-pascal mailing list