[Lazarus] Why is there a define switch UseCThreads?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

[Lazarus] Why is there a define switch UseCThreads?

Free Pascal - Lazarus mailing list
I have ported a console application from Windows to Linux (Raspbian
Buster) and I got to wonder about the check for a defined symbol
appearing in the beginning of the code as produced by the Lazarus
template:

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}

Would it not be enough to use this instead:
uses
  {$IFDEF UNIX}
  cthreads,
  {$ENDIF}

Is there a heavy hit on perfortmance or such if the conditional is not
used but instead just checking if we are on UNIX?

What happens if one does not use threads in ones code but removes the
conditional UseCThreads as shown above?

For example if I am using Indy10 objects they are threaded so in that
case I assume I need to use cthreads. But in any other case, how can I
know that some used package might rely on threads and so needs this
uses clause?

Basically:
What damage does it do if cthreads are in the uses clause but no
thread appears in the program code (yet)?


--
Bo Berglund
Developer in Sweden

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Why is there a define switch UseCThreads?

Free Pascal - Lazarus mailing list
Bo Berglund via lazarus <[hidden email]> schrieb am So., 10. Nov. 2019, 23:29:
I have ported a console application from Windows to Linux (Raspbian
Buster) and I got to wonder about the check for a defined symbol
appearing in the beginning of the code as produced by the Lazarus
template:

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}

Would it not be enough to use this instead:
uses
  {$IFDEF UNIX}
  cthreads,
  {$ENDIF}

Is there a heavy hit on perfortmance or such if the conditional is not
used but instead just checking if we are on UNIX?

What happens if one does not use threads in ones code but removes the
conditional UseCThreads as shown above?

For example if I am using Indy10 objects they are threaded so in that
case I assume I need to use cthreads. But in any other case, how can I
know that some used package might rely on threads and so needs this
uses clause?

Basically:
What damage does it do if cthreads are in the uses clause but no
thread appears in the program code (yet)?

The "damage" is that your application will link against the C library. Sometimes that's not desirable and quite some FPC code can be used without that (e.g. the compiler itself does not need to link against the C library and thus the binary is usable on various Linux distributions and versions). 

Regards, 
Sven 

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Why is there a define switch UseCThreads?

Free Pascal - Lazarus mailing list
On Mon, 11 Nov 2019 00:20:59 +0100, Sven Barth via lazarus
<[hidden email]> wrote:

>Bo Berglund via lazarus <[hidden email]> schrieb am So., 10.
>Nov. 2019, 23:29:
>
>> I have ported a console application from Windows to Linux (Raspbian
>> Buster) and I got to wonder about the check for a defined symbol
>> appearing in the beginning of the code as produced by the Lazarus
>> template:
>>
>> uses
>>   {$IFDEF UNIX}{$IFDEF UseCThreads}
>>   cthreads,
>>   {$ENDIF}{$ENDIF}
>>
>> Would it not be enough to use this instead:
>> uses
>>   {$IFDEF UNIX}
>>   cthreads,
>>   {$ENDIF}
>>
>> Is there a heavy hit on perfortmance or such if the conditional is not
>> used but instead just checking if we are on UNIX?
>>
>> What happens if one does not use threads in ones code but removes the
>> conditional UseCThreads as shown above?
>>
>> For example if I am using Indy10 objects they are threaded so in that
>> case I assume I need to use cthreads. But in any other case, how can I
>> know that some used package might rely on threads and so needs this
>> uses clause?
>>
>> Basically:
>> What damage does it do if cthreads are in the uses clause but no
>> thread appears in the program code (yet)?
>>
>
>The "damage" is that your application will link against the C library.
>Sometimes that's not desirable and quite some FPC code can be used without
>that (e.g. the compiler itself does not need to link against the C library
>and thus the binary is usable on various Linux distributions and versions).
>

So if one does not enable use of cthreads there are still threads
available also on Linux?
I interpreted the existence of this switch as "if you want to use
threads on Linux you need to enable UseCThreads"...

If I do not have cthreads as a uses item but still want to use for
example Indy10, will it still work?


--
Bo Berglund
Developer in Sweden

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Why is there a define switch UseCThreads?

Free Pascal - Lazarus mailing list
In reply to this post by Free Pascal - Lazarus mailing list
On 11/10/19 11:29 PM, Bo Berglund via lazarus wrote:

> I have ported a console application from Windows to Linux (Raspbian
> Buster) and I got to wonder about the check for a defined symbol
> appearing in the beginning of the code as produced by the Lazarus
> template:
>
> uses
>    {$IFDEF UNIX}{$IFDEF UseCThreads}
>    cthreads,
>    {$ENDIF}{$ENDIF}
>
> Would it not be enough to use this instead:
> uses
>    {$IFDEF UNIX}
>    cthreads,
>    {$ENDIF}

AFAIK, in lazarus trunk there's no more {$IFDEF UseCThreads} when
creating new project, only {$IFDEF UNIX}cthreads{$ENDIF}

zeljko
--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Why is there a define switch UseCThreads?

Free Pascal - Lazarus mailing list
In reply to this post by Free Pascal - Lazarus mailing list
Bo Berglund via lazarus <[hidden email]> schrieb am Mo., 11. Nov. 2019, 08:38:
On Mon, 11 Nov 2019 00:20:59 +0100, Sven Barth via lazarus
<[hidden email]> wrote:

>Bo Berglund via lazarus <[hidden email]> schrieb am So., 10.
>Nov. 2019, 23:29:
>
>> I have ported a console application from Windows to Linux (Raspbian
>> Buster) and I got to wonder about the check for a defined symbol
>> appearing in the beginning of the code as produced by the Lazarus
>> template:
>>
>> uses
>>   {$IFDEF UNIX}{$IFDEF UseCThreads}
>>   cthreads,
>>   {$ENDIF}{$ENDIF}
>>
>> Would it not be enough to use this instead:
>> uses
>>   {$IFDEF UNIX}
>>   cthreads,
>>   {$ENDIF}
>>
>> Is there a heavy hit on perfortmance or such if the conditional is not
>> used but instead just checking if we are on UNIX?
>>
>> What happens if one does not use threads in ones code but removes the
>> conditional UseCThreads as shown above?
>>
>> For example if I am using Indy10 objects they are threaded so in that
>> case I assume I need to use cthreads. But in any other case, how can I
>> know that some used package might rely on threads and so needs this
>> uses clause?
>>
>> Basically:
>> What damage does it do if cthreads are in the uses clause but no
>> thread appears in the program code (yet)?
>>
>
>The "damage" is that your application will link against the C library.
>Sometimes that's not desirable and quite some FPC code can be used without
>that (e.g. the compiler itself does not need to link against the C library
>and thus the binary is usable on various Linux distributions and versions).
>

So if one does not enable use of cthreads there are still threads
available also on Linux?
I interpreted the existence of this switch as "if you want to use
threads on Linux you need to enable UseCThreads"...

If I do not have cthreads as a uses item but still want to use for
example Indy10, will it still work?

You asked what the damage is if one does not use threads. 

If you use threads then you *must* use the cthreads unit on Unix platforms. 

Regards, 
Sven 

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Why is there a define switch UseCThreads?

Free Pascal - Lazarus mailing list
In reply to this post by Free Pascal - Lazarus mailing list
On Mon, 11 Nov 2019 08:59:43 +0100, zeljko via lazarus
<[hidden email]> wrote:

>On 11/10/19 11:29 PM, Bo Berglund via lazarus wrote:
>> I have ported a console application from Windows to Linux (Raspbian
>> Buster) and I got to wonder about the check for a defined symbol
>> appearing in the beginning of the code as produced by the Lazarus
>> template:
>>
>> uses
>>    {$IFDEF UNIX}{$IFDEF UseCThreads}
>>    cthreads,
>>    {$ENDIF}{$ENDIF}
>>
>> Would it not be enough to use this instead:
>> uses
>>    {$IFDEF UNIX}
>>    cthreads,
>>    {$ENDIF}
>
>AFAIK, in lazarus trunk there's no more {$IFDEF UseCThreads} when
>creating new project, only {$IFDEF UNIX}cthreads{$ENDIF}
>
Thanks,
then the idea is that if building for Linux and you use threads
anywhere you need to put this first in the project file, right?
So in my case since I know that Indy10 uses a lot of threads I have to
do that.

--
Bo Berglund
Developer in Sweden

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Why is there a define switch UseCThreads?

Free Pascal - Lazarus mailing list
On 11/11/19 6:03 PM, Bo Berglund via lazarus wrote:

> then the idea is that if building for Linux and you use threads
> anywhere you need to put this first in the project file, right?

Lazarus trunk -> New project automatically adds cthreads enclosed with
IFDEF UNIX, if you create your program manually the you should add it
manually there.

z.

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus