[m-rev.] For review: Java implementation of IO library

James Goddard goddardjames at yahoo.com
Wed Jan 14 16:31:46 AEDT 2004


 --- Fergus Henderson <fjh at cs.mu.OZ.AU> wrote: > On 14-Jan-2004, James Goddard
<goddardjames at yahoo.com> wrote:
> > +	private static class StreamPipe extends java.lang.Thread {
> ...
> > +		boolean live			= true;
> 
> If that field is modified from another thread,
> does it need to be declared `volatile' or something like that?
> 

Yes.. This is probably neater:

diff -u io.m io.m
--- io.m        14 Jan 2004 03:50:24 -0000
+++ io.m        14 Jan 2004 05:29:03 -0000
@@ -5108,7 +5108,6 @@
        private static class StreamPipe extends java.lang.Thread {
                MR_MercuryFileStruct in;
                MR_MercuryFileStruct out;
-               boolean live                    = true;
                boolean closeOutput             = false;
                java.lang.Exception exception   = null;

@@ -5125,9 +5124,9 @@

                public void run() {
                        try {
-                               while (live) {
+                               while (true) {
                                        int b = in.read_char();
-                                       if (b == -1) {
+                                       if (b == -1 || interrupted()) {
                                                break;
                                        }
                                        out.putc(b);
@@ -7389,6 +7388,7 @@
        try {
                java.lang.Process process = java.lang.Runtime.getRuntime().
                                exec(Command);
+
                StreamPipe stdin = new StreamPipe(mercury_stdin,
                                process.getOutputStream());
                StreamPipe stdout = new StreamPipe(process.getInputStream(),
@@ -7402,9 +7402,12 @@
                Status  = process.waitFor();
                Msg     = null;

-               stdin.live = false;
-               stdout.live = false;
-               stderr.live = false;
+               // The StreamPipes are killed off after the Process is
+               // finished, so as not to waste CPU cycles with pointless
+               // threads.
+               stdin.interrupt();
+               stdout.interrupt();
+               stderr.interrupt();

                if (stdin.exception != null) {
                        throw stdin.exception;


http://personals.yahoo.com.au - Yahoo! Personals
New people, new possibilities. FREE for a limited time.
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list