[fpc-pascal] cthreads

2014-07-25 Thread Juha Manninen
I was asked why a threaded application compiles on Linux without uses
cthreads but it does not work.
cthreads must _always_ be added to uses section.
I had no answer to that. IMO such errors should be trapped at
compile-time, not at run-time.
Could it be fixed somehow?
Many people experience the same run-time error about too many
concurrent threads. They must search the net and ask questions while
(I guess) the problem could be solved by forcing a compilation error.

Juha
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] cthreads

2014-07-25 Thread Michael Van Canneyt



On Fri, 25 Jul 2014, Juha Manninen wrote:


I was asked why a threaded application compiles on Linux without uses
cthreads but it does not work.
cthreads must _always_ be added to uses section.
I had no answer to that. IMO such errors should be trapped at
compile-time, not at run-time.
Could it be fixed somehow?


No, because there is no way to detect that threads are actually used in the 
program.

The TThread class is a class like any other, with no special treatment.
It is in the classes unit.

The fact that it is there does not mean it is actually used.
That goes for a lot of code.

You don't even need to use the TThread class; 
you can perfectly program threads with just the threadmanager.


In retrospect, Borland made an error declaring tthread in the classes unit.
It should have been put in a separate unit. That would have made detection 
easier.


Many people experience the same run-time error about too many
concurrent threads. They must search the net and ask questions while
(I guess) the problem could be solved by forcing a compilation error.


Or - for once in their life - people could read the documentation.

http://www.freepascal.org/docs-html/prog/progse43.html

It is remarked TWICE that you must include the cthreads unit.

I will add a remark in the classes unit TThread class documentation, 
to make it even more obvious.


Michael.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] cthreads

2014-07-25 Thread Mark Morgan Lloyd

Michael Van Canneyt wrote:

On Fri, 25 Jul 2014, Juha Manninen wrote:


I was asked why a threaded application compiles on Linux without uses
cthreads but it does not work.
cthreads must _always_ be added to uses section.
I had no answer to that. IMO such errors should be trapped at
compile-time, not at run-time.
Could it be fixed somehow?


No, because there is no way to detect that threads are actually used in 
the program.


I will add a remark in the classes unit TThread class documentation, to 
make it even more obvious.


Is there scope for improving the error message?

Is there a scenario in which a program that sometimes uses threads (e.g. 
if it realises it's being asked to do a big job which can be 
parallelised) could start without giving the error message? This would 
make the situation more serious, since it would require that the 
programmer did some /real/ testing before shipping his code :-)


--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] cthreads

2014-07-25 Thread Michael Van Canneyt



On Fri, 25 Jul 2014, Mark Morgan Lloyd wrote:


Michael Van Canneyt wrote:

On Fri, 25 Jul 2014, Juha Manninen wrote:


I was asked why a threaded application compiles on Linux without uses
cthreads but it does not work.
cthreads must _always_ be added to uses section.
I had no answer to that. IMO such errors should be trapped at
compile-time, not at run-time.
Could it be fixed somehow?


No, because there is no way to detect that threads are actually used in the 
program.


I will add a remark in the classes unit TThread class documentation, to 
make it even more obvious.


Is there scope for improving the error message?

Is there a scenario in which a program that sometimes uses threads (e.g. if 
it realises it's being asked to do a big job which can be parallelised) could 
start without giving the error message? This would make the situation more 
serious, since it would require that the programmer did some /real/ testing 
before shipping his code :-)


Not sure what you mean.

The error only appears if you call a function that relies on the threading manager, 
never at the start of the program. It's slightly more complicated than this, but 
it boils down to that.


So the fact that the program started doesn't mean there won't be an error further 
down the line. But that is IMHO no different from many other programming errors, 
such as trying to save preferences in a file in a directory that doesn't exist. 
You should always test all cases.



Michael.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] cthreads

2014-07-25 Thread Fabio Luis Girardi
The same question that I posted on bugtracker:

Linux, BSD, Unix, has another threaddriver than cthreads? If no, why not
make cthreads unit the default threaddriver for Unix?


2014-07-25 7:33 GMT-03:00 Michael Van Canneyt mich...@freepascal.org:



 On Fri, 25 Jul 2014, Mark Morgan Lloyd wrote:

  Michael Van Canneyt wrote:

 On Fri, 25 Jul 2014, Juha Manninen wrote:

  I was asked why a threaded application compiles on Linux without uses
 cthreads but it does not work.
 cthreads must _always_ be added to uses section.
 I had no answer to that. IMO such errors should be trapped at
 compile-time, not at run-time.
 Could it be fixed somehow?


 No, because there is no way to detect that threads are actually used in
 the program.


  I will add a remark in the classes unit TThread class documentation, to
 make it even more obvious.


 Is there scope for improving the error message?

 Is there a scenario in which a program that sometimes uses threads (e.g.
 if it realises it's being asked to do a big job which can be parallelised)
 could start without giving the error message? This would make the situation
 more serious, since it would require that the programmer did some /real/
 testing before shipping his code :-)


 Not sure what you mean.

 The error only appears if you call a function that relies on the threading
 manager, never at the start of the program. It's slightly more complicated
 than this, but it boils down to that.

 So the fact that the program started doesn't mean there won't be an error
 further down the line. But that is IMHO no different from many other
 programming errors, such as trying to save preferences in a file in a
 directory that doesn't exist. You should always test all cases.


 Michael.

 ___
 fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
 http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal




-- 
The best regards,

Fabio Luis Girardi
PascalSCADA Project
http://sourceforge.net/projects/pascalscada
http://www.pascalscada.com
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] cthreads

2014-07-25 Thread Ewald
On 07/25/2014 03:04 PM, Fabio Luis Girardi wrote:
 The same question that I posted on bugtracker:

 Linux, BSD, Unix, has another threaddriver than cthreads? If no, why
 not make cthreads unit the default threaddriver for Unix?

I read somewhere some time ago that the main reason for this was that
FPC has no dependency to libc under normal circumstances. Making
cthreads the default thread manager would thus add a dependency to libc.


-- 
Ewald

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] cthreads

2014-07-25 Thread Fabio Luis Girardi
2014-07-25 10:10 GMT-03:00 Ewald ew...@yellowcouch.org:

 On 07/25/2014 03:04 PM, Fabio Luis Girardi wrote:
  The same question that I posted on bugtracker:
 
  Linux, BSD, Unix, has another threaddriver than cthreads? If no, why
  not make cthreads unit the default threaddriver for Unix?

 I read somewhere some time ago that the main reason for this was that
 FPC has no dependency to libc under normal circumstances. Making
 cthreads the default thread manager would thus add a dependency to libc.


 --
 Ewald




-- 
The best regards,

Fabio Luis Girardi
PascalSCADA Project
http://sourceforge.net/projects/pascalscada
http://www.pascalscada.com
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] cthreads

2014-07-25 Thread Sven Barth
Am 25.07.2014 15:11 schrieb Ewald ew...@yellowcouch.org:

 On 07/25/2014 03:04 PM, Fabio Luis Girardi wrote:
  The same question that I posted on bugtracker:
 
  Linux, BSD, Unix, has another threaddriver than cthreads? If no, why
  not make cthreads unit the default threaddriver for Unix?

 I read somewhere some time ago that the main reason for this was that
 FPC has no dependency to libc under normal circumstances. Making
 cthreads the default thread manager would thus add a dependency to libc.

This is correct. It's the same reason for the widestring manager provided
by cwstrings unit. Though 2.7.1 now has a Pascal only widestring manager as
well. :)

Regards,
Sven
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] cthreads

2014-07-25 Thread Marco van de Voort
In our previous episode, Fabio Luis Girardi said:
 The same question that I posted on bugtracker:
 
 Linux, BSD, Unix, has another threaddriver than cthreads? 

No.

 If no, why not
 make cthreads unit the default threaddriver for Unix?

Because then all apps are linked to it, also the ones that don't need
threads. Same for clocale and cwstrings.
 
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal