[m-dev.] Interleaved output in hlc.gc.par

Paul Bone paul at bone.id.au
Thu Sep 17 16:36:42 AEST 2015


While I was testing the boehm_gc changes in hlc.gc.par tl_backjump_test
failed as follows:

paul at oxygen> diff -u tests/hard_coded/tl_backjump_test.{exp,out}
--- tests/hard_coded/tl_backjump_test.exp       2014-11-12 12:16:20.420852421 +1100
+++ tests/hard_coded/tl_backjump_test.out       2015-09-17 14:58:47.463777533 +1000
@@ -20,9 +20,8 @@
 (TID: #2) solution 2, 2, 2
 (TID: #2) label C = 3, (14)
 (TID: #2) Solutions:
-(TID: #2) {1, 1, 3},
-(TID: #2) {2, 1, 1},
-(TID: #2) {2, 2, 2}
+(TID: #2) (TID: #3) label C = 3, (14)
+(TID: #2) (TID: #3) {2{, 21, , 1},
 (TID: #3) label A = 1, (0)
 (TID: #3) label B = 1, (1)
 (TID: #3) label C = 1, (2)
@@ -43,8 +42,6 @@
 (TID: #3) label C = 1, (12)
 (TID: #3) label C = 2, (13)
 (TID: #3) solution 2, 2, 2
-(TID: #3) label C = 3, (14)
 (TID: #3) Solutions:
-(TID: #3) {1, 1, 3},
-(TID: #3) {2, 1, 1},
+(TID: #3) {{11, , 11, , 33}},
 (TID: #3) {2, 2, 2}

As this is a multithreaded test the test suite sorts output lines so that
interleaving does not affect the result of the test.  However the output of the
threads is interleaved _within_ lines.

The test case uses io.format to print its results and I believe that the
compiler is optimising io.format into multiple calls to io.write_string (and
others) and these calls are being interleaved between the threads.

Should a user reasonably expect calls to io.format to be atomic with respect
to the IO state?  I ask because this creates an inconsistency.

    hello(!IO) :-
        io.write_string("Hello ", !IO),
        io.write_string("world!", !IO).

We generally don't expect hello/2 to be atomic with respect to IO.  (THis is
the semantics of thread.spawn, not pararallel conjunctions)  But by
expecting this of io.format we create a double standard.  Is this okay?

If so we can update the io.format optimisation to lock and unlock the output
stream within the IO state to prevent interleaving like this.

Cheers.


-- 
Paul Bone



More information about the developers mailing list