@@ -4,33 +4,43 @@ var writes = 0;
44var pos ;
55var item ;
66var temp ;
7- for ( var cycleStart = 0 ; cycleStart <= N - 2 ; cycleStart ++ ) {
7+ for ( var cycleStart = 0 ; cycleStart <= N - 2 ; cycleStart ++ ) {
88 item = D [ cycleStart ] ;
99 pos = cycleStart ;
10- for ( var i = cycleStart + 1 ; i <= N - 1 ; i ++ ) {
10+ tracer . _select ( cycleStart ) ;
11+
12+ for ( var i = cycleStart + 1 ; i <= N - 1 ; i ++ ) {
13+ tracer . _select ( i ) . _wait ( ) . _deselect ( i ) ;
1114 if ( D [ i ] < item ) {
1215 pos ++ ;
1316 }
1417 }
1518 if ( pos == cycleStart ) {
19+ tracer . _deselect ( cycleStart ) ;
1620 continue ;
1721 }
1822 while ( item == D [ pos ] ) {
1923 pos ++ ;
2024 }
25+
2126 temp = D [ pos ] ;
2227 D [ pos ] = item ;
2328 item = temp ;
2429
25- logger . _print ( 'Rewrite ' + D [ pos ] + ' to index ' + pos ) ;
26-
30+ if ( pos !== cycleStart ) {
31+ logger . _print ( 'Rewrite ' + D [ pos ] + ' to index ' + pos + '; the next value to rewrite is ' + item ) ;
32+ } else {
33+ logger . _print ( 'Rewrite ' + D [ pos ] + ' to index ' + pos ) ;
34+ }
35+ tracer . _select ( pos ) . _wait ( ) . _deselect ( pos ) ;
2736 tracer . _notify ( pos , D [ pos ] ) . _notify ( cycleStart , D [ cycleStart ] ) . _wait ( ) ;
28- tracer . _denotify ( pos ) . _denotify ( pos ) ;
29-
37+ tracer . _denotify ( pos ) . _denotify ( cycleStart ) ;
3038
3139 while ( pos != cycleStart ) {
3240 pos = cycleStart ;
41+
3342 for ( i = cycleStart + 1 ; i <= N - 1 ; i ++ ) {
43+ tracer . _select ( i ) . _wait ( ) . _deselect ( i ) ;
3444 if ( D [ i ] < item ) {
3545 pos ++ ;
3646 }
@@ -39,14 +49,19 @@ for( var cycleStart=0; cycleStart<=N-2; cycleStart++ ){
3949 while ( item == D [ pos ] ) {
4050 pos ++ ;
4151 }
52+
4253 temp = D [ pos ] ;
4354 D [ pos ] = item ;
4455 item = temp ;
4556
46- logger . _print ( 'Rewrite ' + D [ pos ] + ' to index ' + pos ) ;
47-
57+ if ( pos !== cycleStart ) {
58+ logger . _print ( 'Rewrite ' + D [ pos ] + ' to index ' + pos + '; the next value to rewrite is ' + item ) ;
59+ } else {
60+ logger . _print ( 'Rewrite ' + D [ pos ] + ' to index ' + pos ) ;
61+ }
62+ tracer . _select ( pos ) . _wait ( ) . _deselect ( pos ) ;
4863 tracer . _notify ( pos , D [ pos ] ) . _notify ( cycleStart , D [ cycleStart ] ) . _wait ( ) ;
49- tracer . _denotify ( pos ) . _denotify ( pos ) ;
64+ tracer . _denotify ( pos ) . _denotify ( cycleStart ) ;
5065
5166 writes ++ ;
5267 }
0 commit comments