<html>
<head>
<style>
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
FONT-SIZE: 10pt;
FONT-FAMILY:Tahoma
}
</style>
</head>
<body class='hmmessage'>
Randy, just because the initialization happens early does not mean you can't affect the behavior later. The type can be changed at initialization time, and then the instance configured later. Unless you are worried about other module initializers ignorantly calling stdout.Wr() and causing the console to appear? If so, yeah.<BR>
<BR>
How about @M3 command line parameters instead?<BR>
At least they aren't "sticky" and can be more easily localized to a single process.<BR>
I ignore sh's feature here usually, and in this case that makes good sense.<BR>
"Command line parameters are better than environment variables".<BR>
Supporting both is reasonable.<BR>
However, if so, and if it is an @M3 variable, there should perhaps be one variable to contain @M3 options??<BR>
<BR>
Still I'm not a fan of globals like this. I think it should be configurable per type instantiation.<BR>
<BR>
You could also imagine that one variable is the "during initialization time" configuration, and then once Main starts, another configuration takes over, since by then whoever wants to set it has had a chance to run.<BR>
<BR>
Btw, sleazy, but you could also make it a built-time configuration. You could easily build your m3core.dll to have one default behavior, while everyone else's has another.<BR>
<BR>
- Jay<BR><BR>
<BLOCKQUOTE>
<HR>
Date: Wed, 18 Jun 2008 23:18:59 -0400<BR>From: rcoleburn@scires.com<BR>To: m3devel@elegosoft.com<BR>Subject: Re: [M3devel] proposal for dealing with lazy console--please review and comment!<BR><BR>
<META content="Microsoft SafeHTML" name=Generator>
<STYLE>
.ExternalClass .EC_hmmessage P
{padding:0px;}
.ExternalClass body.EC_hmmessage
{font-size:10pt;font-family:Tahoma;}
</STYLE>
<DIV>Jay:</DIV>
<DIV> </DIV>
<DIV>I'd be satisfied just to deal with this on a per program instance, rather than at a thread level. Indeed, I'm not sure it makes sense on a per thread level. The Stdio module and global vars are shared by all code in the program process.</DIV>
<DIV> </DIV>
<DIV>I'm wondering if it might be better at this point to use environment variables to control the behavior. The current implementation initializes everything during module initialization at program startup. Thus, this occurs before dependent modules get a chance to run and influence the behavior.</DIV>
<DIV> </DIV>
<DIV>Perhaps the lazy console allocation should be the default unless a certain environment variable is set, say CM3_LazyConsole=FALSE. In this case the initialization code would turn off the lazy allocation and in the case of a GUI-mode program on Windows the Stdio.stdin/stdout/stderr would be NIL. If CM3_LazyConsole=TRUE or is not defined, you would get a lazy allocated console on Windows GUI-mode programs and a regular console otherwise.</DIV>
<DIV> </DIV>
<DIV>This approach has the advantage that no interfaces have to change.</DIV>
<DIV> </DIV>
<DIV>Of course, if folks want to add finer grains of control as you suggest, that would be ok. I just want to be able to prevent the popup of the lazy allocated console.</DIV>
<DIV> </DIV>
<DIV>I'm willing to make the modifications to the code unless someone objects to my approach.</DIV>
<DIV> </DIV>
<DIV>Regards,</DIV>
<DIV>Randy<BR><BR>>>> Jay <jayk123@hotmail.com> 6/18/2008 1:20 PM >>><BR>Randy, really, the vast majority of behavior is undocumented and not controllable.<BR>However I agree making this controllable is perfectly reasonable.<BR>The folks that did this were I believe Critical Mass, between "4.1" and "5.1", though granted the history is not completely known, just that 4.1 and earlier doesn't behave this way.<BR> <BR>I strongly advocate a type-based solution here.<BR> <BR>However, I believe there are several bits per handle however, not one.<BR>Not at the Win32 level, but in terms of the control you would want in the Modula-3.<BR> <BR>There is:<BR> Is the console visible?<BR> Either because it started that way, or because "someone" has written to it already.<BR> <BR> Should any/no write make it visible?<BR> <BR> Should "this particular" write make it visible?<BR> <BR>That is, you probably want the ability to avoid the console becoming visible.<BR>You probably want the ability to control this globally or per-write.<BR>Maybe even per-thread and not just per-process.<BR>And, say, if there is a severe error, you want to enable it becoming visible.<BR>And, say, if someone else wrote an error and made it visible and now you just have a warning, you might want to "piggy back" on the visibility and go ahead and print.<BR> <BR>You may even want to rehide the console, if that is possible.<BR>(Could expose this in the interface and it make it a nop..)<BR> <BR>Controlling this per-thread or per-process or per-write is actually pretty problematic.<BR> Because even if it is per-thread or per-process, I believe it should at the same time be per-handle. I should be able to block revelation on stdout for current thread, and then restore it when I am done. While leaving stderr unaltered, on the theory that stderr output is more important. Similarly per-process. But then each handle has per-thread locals. Ok, duh, per-process doesn't make sense, that's the same as per-handle.<BR> <BR>Controlling it per-handle is not problematic. Each handle would just have a fixed set of extra bits.<BR> <BR>I believe controlling it module-wide either per-process or per-thread *might* be interesting, but less so. Globals are bad. Even if hidden behind thread-safe functions. Just because Modula-3 nicely contains process-globals in modules, doesn't make them acceptable. I think modules are overrated actually, and "objects" -- instances of types are much more important. Modula-3 does "work", just that I should in general create Foo.T data and pass them as the first parameter to Foo.DoSomething. Programming is much more "type based" than "module based" imho. I know there is some disagreement here, but I'm not sure there is much.<BR> <BR>Really, there is a general issue of globals vs. parameters to functions, throughout a callstack.<BR> <BR>One implementation strategy would be to able to create a "wrapper" object.<BR>You would set the "policy" on that object -- perhaps via which type you created in the first place. You would pass that around to all your code. That would achieve per-thread, or per-whatever-you want, BUT it'd require you pass it around to all of your code.<BR> <BR>It is a tough discpline to really pass around all parameters, and not rely on some larger "global" or per-thread context. Thread locals and globals quite stink, and "plumbing the full depths of a call tree" can also be quite difficult". The problem, you know, of "oops, I forgot to add a parameter in lots of places. What do I do now? I know, I'll make a thread local, set it at the top of the call tree, check it in the middle or at the bottom, but not pass it all around..." It's a difficult problem. Much of the code in a particular call tree might not know or care about what the top and bottom care about, but somehow should be able to ferry along "context". Thread locals are so tempting and oh so problematic...<BR> <BR> - Jay<BR><BR></DIV>
<BLOCKQUOTE>
<HR>
Date: Wed, 18 Jun 2008 12:50:29 -0400<BR>From: rcoleburn@scires.com<BR>To: m3devel@elegosoft.com<BR>Subject: Re: [M3devel] proposal for dealing with lazy console--please review and comment!<BR><BR>
<DIV>Hi Rodney:</DIV>
<DIV> </DIV>
<DIV>Thanks for your reply.</DIV>
<DIV> </DIV>
<DIV>The issue is that for cm3 on Windows you can specify -gui as a command line option. This option causes the program to be built as a Windows GUI-mode application, rather than as a console application. For a GUI-mode application, the Stdio file handles are NIL because it has no console.</DIV>
<DIV> </DIV>
<DIV>Seemingly, to prevent a lot of errors when trying to read/write Stdio, some folks introduced the idea of a lazy console post cm3 v4.1. What happens now "under the covers" is that on a GUI-mode program the Stdio file handles are allocated as Lazy Consoles. Then, whenever Stdio.stdout/stderr/stdin is used, the underlying code realizes the first use and magically allocates a new console window on the fly. This console window pops up on the screen on top of your GUI-mode window.</DIV>
<DIV> </DIV>
<DIV>My objection is that this behavior is not documented in any interface and the programmer has no way to control the behavior. I want to make such control possible.</DIV>
<DIV> </DIV>
<DIV>Hope this explanation helps a bit.</DIV>
<DIV> </DIV>
<DIV>Regards,</DIV>
<DIV>Randy<BR><BR>>>> "rodney.bates" <rodney.bates@wichita.edu> 6/18/2008 10:36 AM >>><BR>I don't understand well enough what it means for a console<BR>to be lazily-allocated, but I wonder if it makes any sense to<BR>allow client code, by assignments to Stdio.stdout_Islazy, to <BR>change this property in general. Why would a FileWr.T ever<BR>be lazy, for example? Can't the cases where the lazy property <BR>needs to be controlled by client code be enclosed inside procedures<BR>that do it in a thread-safe way?<BR><BR>>4. Modify Stdio implementation to properly initialize the new<BR>>variables during module initialization.<BR>>This change will be transparent to all clients.<BR>><BR>>Now, with these changes, it will be possible for a client to know<BR>>whether stdout, stderr, and/or stdin represent lazily allocated<BR>>consoles or not, then act accordingly.<BR>><BR>>For example, if I want to make sure messages written to stdout are<BR>>recorded even for a GUI-app, but I don't want a popup, I could do the<BR>>following:<BR>> IF (Stdio.stdOut_IsLazy) OR (Stdio.stdout = NIL)<BR>> THEN<BR>> Stdio.stdout := FileWr.Open("myLogFile.txt");<BR>> Stdio.stdOut_IsLazy := FALSE;<BR>> END;<BR>>Now the above code fragment does show the possibility of a race<BR>>condition in multi-threaded code.<BR>><BR><BR>Rodney Bates<BR>Retired assistant professor<BR>Computer Science<BR><BR><BR></DIV></BLOCKQUOTE></BLOCKQUOTE></body>
</html>