Re: [fpc-pascal] What's the deal with CloseThread?

2013-04-23 Thread Marco van de Voort
In our previous episode, Anthony Walter said:
> I was looking at threading support in the System unit and also in the
> TThread class.
> 
> According to the documentation at
> http://www.freepascal.org/docs-html/rtl/system/closethread.html
> 
> CloseThread must be called on any thread started with BeginThread. It must
> be called after the thread has ended (either by exiting the thread function
> or after calling EndThread).

Yes, Closethread closes possible handles deallocating anything that must
remain allocated to read out thread results.

> Looking at the TThread class, which does indeed use BeginThread in
> TThread.SysCreate (tthread.inc), I see no corresponding call the
> CloseThread. I grepped the entire fpc source tree and found no references
> anywhere to any code which calls CloseThread.

_BUT_ tthread.inc's are target dependent and thus don't necessarily go
through the platform independent procedural "beginthread" interface. 
(actually, some parts of the procedural interface, including chlosethread
were only crafted _after_ tthreads completion, when it turned out that the
procedural interface had leaks, and the tthread not)

E.g. the Closehandle at rtl/win/tthread.inc:35 does the same thing.
 
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] What's the deal with CloseThread?

2013-04-23 Thread Anthony Walter
I get your point about Windows + CloseHandle

But I'm still confused with regards to every other platform. You say yes,
affirming the documentation ... that CloseThread must be called ... nowhere
in any of the platform code I've search is CloseThread used, ever. (even
though BeginThread is used)
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] What's the deal with CloseThread?

2013-04-23 Thread Sven Barth

Am 23.04.2013 09:56, schrieb Anthony Walter:

I get your point about Windows + CloseHandle

But I'm still confused with regards to every other platform. You say 
yes, affirming the documentation ... that CloseThread must be called 
... nowhere in any of the platform code I've search is CloseThread 
used, ever. (even though BeginThread is used)
The only RTL that currently really does something inside CloseThread is 
the Windows RTL which calls CloseHandle like TThread.SysDestroy does. So 
it would probably best to adjust the TThread implementation to always 
call CloseThread as well and remove the CloseHandle in the Windows 
implementation of TThread.SysDestroy call...


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


Re: [fpc-pascal] What's the deal with CloseThread?

2013-04-23 Thread Marco van de Voort
In our previous episode, Anthony Walter said:
> I get your point about Windows + CloseHandle
> 
> But I'm still confused with regards to every other platform. You say yes,
> affirming the documentation ... that CloseThread must be called ... nowhere
> in any of the platform code I've search is CloseThread used, ever. (even
> though BeginThread is used)

True. But that only means that the beginthread interface is relatively
little used because everybody uses tthread.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] What's the deal with CloseThread?

2013-04-23 Thread Anthony Walter
On Tue, Apr 23, 2013 at 7:13 AM, Marco van de Voort  wrote:

> True. But that only means that the beginthread interface is relatively
> little used because everybody uses tthread.


But on i386-linux TThread does use BeginThread and never calls CloseThread.
So that seems contrary to the rule we are discussing in the documentation.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] What's the deal with CloseThread?

2013-04-23 Thread Marco van de Voort
In our previous episode, Anthony Walter said:
> > True. But that only means that the beginthread interface is relatively
> > little used because everybody uses tthread.
> 
> But on i386-linux TThread does use BeginThread and never calls CloseThread.
> So that seems contrary to the rule we are discussing in the documentation.

The TThread code was never specified in terms of the procedural api. As said
the procedural api largely came after tthread was stable.

Probably at some point calls to the threadmanager were substituted with
calls to beginthread.

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


Re: [fpc-pascal] Object Pascal Grammar in EBNF like style

2013-04-23 Thread Kenneth Cochran
Just curious how your efforts turned out?


On Fri, Mar 22, 2013 at 9:59 AM, Graeme Geldenhuys
wrote:

> On 2013-03-22 13:29, Michael Van Canneyt wrote:
> >
> > That looks dangerously much, almost verbatim, like the appendix A of the
> > Delphi language guide as found in the D7 manual.
>
> Umm, I don't have the Delphi manuals, but I do have the Kylix 3 manuals.
> I see what you mean. I didn't copy it from the Kylix 3 manual though, I
> got it from the following URL:
>
>http://delphi.wikia.com/wiki/Object_Pascal_Grammar
>
> Would it make a difference though? EBNF for a language grammar should be
> pretty much identical to any other EBNF of the same language. The order
> of the definitions might change slightly, but the language grammar would
> still be the same.
>
>
> Regards,
>   - Graeme -
>
> --
> fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
> http://fpgui.sourceforge.net/
>
> ___
> fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] What's the deal with CloseThread?

2013-04-23 Thread Anthony Walter
On Tue, Apr 23, 2013 at 9:22 AM, Marco van de Voort  wrote:

> The TThread code was never specified in terms of the procedural api. As
> said
> the procedural api largely came after tthread was stable.
>
> Probably at some point calls to the threadmanager were substituted with
> calls to beginthread.


BeginThread, EndThread, CloseThread all directly call thread manager
entries behind the scenes, so substituting a call to the thread manager
with a call to any of those functions are the same.

To explain, I am writing my own light threading library and just want to
ensure my housekeeping is being done correctly. Looking at the current
thread system which people use (TThread) and looking at the documentation
for BeginThread, EndThread, CloseThread, there seems to be a discrepancy.
I'd like to know which is correct.

That is, it is okay to call BeginThread and never call CloseThread? Because
that is how TThread currently works, and is in contradiction to the
documentation.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] What's the deal with CloseThread?

2013-04-23 Thread Marco van de Voort
In our previous episode, Anthony Walter said:
> That is, it is okay to call BeginThread and never call CloseThread? Because
> that is how TThread currently works, and is in contradiction to the
> documentation.

If you want split hairs:

It is ok for tthread, since as in tree code it can legally use non published
interfaces, it is not ok for you :_)
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] What's the deal with CloseThread?

2013-04-23 Thread Anthony Walter
Okay, thanks for the replies. I'll stick with what I have know, which is to
use BeginThread, EndThread, CloseThread.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] What's the deal with CloseThread?

2013-04-23 Thread Sven Barth

On 23.04.2013 16:28, Anthony Walter wrote:

That is, it is okay to call BeginThread and never call CloseThread?
Because that is how TThread currently works, and is in contradiction to
the documentation.


And no one bothers to read my answer :(

Again: The only RTL that currently(!) does something inside CloseThread 
is the Windows RTL: it closes the thread handle (which was returned by 
BeginThread and is passed as an argument to CloseThread) using CloseHandle.


The Windows TThread.SysDestroy also calls CloseHandle on the handle 
returned by BeginThread, so the semantic behavior of 
Begin-/End-/CloseThread and TThread is the same.


Nevertheless in my opinion TThread needs to be adjusted so that it calls 
CloseThread for all RTLs and the direct CloseHandle call needs to be 
removed. And this is exactly what I will do now...


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


[fpc-pascal] RAD Studio XE4 Released?

2013-04-23 Thread vfclists .
http://www.h-online.com/developer/news/item/RAD-Studio-XE4-focuses-on-cross-platform-apps-1848176.html

http://www.embarcadero.com/press-releases/embarcadero-technologies-unveils-multi-device-true-native-app-development-suite
-- 
Frank Church

===
http://devblog.brahmancreations.com
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] What's the deal with CloseThread?

2013-04-23 Thread Sven Barth

On 23.04.2013 21:40, Sven Barth wrote:

On 23.04.2013 16:28, Anthony Walter wrote:

That is, it is okay to call BeginThread and never call CloseThread?
Because that is how TThread currently works, and is in contradiction to
the documentation.


And no one bothers to read my answer :(

Again: The only RTL that currently(!) does something inside CloseThread
is the Windows RTL: it closes the thread handle (which was returned by
BeginThread and is passed as an argument to CloseThread) using CloseHandle.

The Windows TThread.SysDestroy also calls CloseHandle on the handle
returned by BeginThread, so the semantic behavior of
Begin-/End-/CloseThread and TThread is the same.

Nevertheless in my opinion TThread needs to be adjusted so that it calls
CloseThread for all RTLs and the direct CloseHandle call needs to be
removed. And this is exactly what I will do now...


Changed in revision 24313.

Regards,
Sven

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


Re: [fpc-pascal] Statically link library

2013-04-23 Thread Darius Blaszyk

On Apr 21, 2013, at 6:35 PM, Ludo Brands wrote:

> A few things wrong in your files:
> - the c program. When you want to link against msvcrt then you better
> use the ms functions;) There is no filesize, or open, or close (the
> latter are deprecated since a while and not present anymore in msvcrt)
> 

> 
> This runs correctly on my system.
> 
> I have attached the modified files and the 2 .a files (windows x86). The
> MakeFile.win created by wxDev-C++ is included. I renamed the
> Output/MingW/Project1.a to libtest.a. When using wxDev-C++ make sure to
> set the file to compile as a C file. Default is C++ and that uses a
> different name mangling.

Thanks Ludo! Works perfectly also here. However for my understanding. Why does 
MinGW find open, filesize etc? Is there some header file that "translates" 
these functions to be compatible with msvcrt? If not I would have to create one 
myself to limit the amount of work I guess.

Regards, Darius


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


Re: [fpc-pascal] What's the deal with CloseThread?

2013-04-23 Thread Anthony Walter
Thanks for so much Sven. I have another question.

Is it okay for a thread to close itself before it's finished? Because I
believe that is what happens when FreeOnTerminate is set to True. Here is a
brief synopsis of what can execute:

In rtl/objpas/classes/classes.inc

Line 168: FreeThread := Thread.FFreeOnTerminate; // captures free on
termiante
Line 173: Thread.Free; // invokes the destructor from within the thread
Line 197: CloseThread(FHandle); // thread is closed in destructor
TThread.Destroy;
Line 174: EndThread(Result); // flow returns here, but the thread was
already closed

So what it looks like is that we expect code inside a thread continue
running after it has been closed.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] What's the deal with CloseThread?

2013-04-23 Thread Anthony Walter
I was read this on MSDN:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms724211(v=vs.85).aspx

"Closing a thread handle does not terminate the associated thread or remove
the thread object. Closing a process handle does not terminate the
associated process or remove the process object. To remove a thread object,
you must terminate the thread, then close all handles to the thread."

So that would see to indicate on Windows at least, that CloseThread should
come after a thread has exited (I assume this should be the case for all
platforms). What this basically translates to is that threads should be
closed after use, but they cannot (or should not) be closed within its own
running thread context. It looks like something is wrong with whatever we
have at the moment.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal