File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -16,5 +16,5 @@ if (isMainThread) {
1616 array [ i ] += value ;
1717 }
1818 console . dir ( [ threadId , array ] ) ;
19- } , 100 ) ;
19+ } , 100 ) ; // change to 10 to see race condition
2020}
Original file line number Diff line number Diff line change @@ -45,5 +45,5 @@ if (isMainThread) {
4545 }
4646 console . dir ( [ threadId , array ] ) ;
4747 semaphore . leave ( ) ;
48- } , 100 ) ;
48+ } , 100 ) ; // change to 10 to see race condition
4949}
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ class CountingSemaphore {
2626
2727if ( isMainThread ) {
2828 const buffer = new SharedArrayBuffer ( 4 ) ;
29- // Try change 10 at next lene to 2 for example
29+ // Try change 10 to 2 at next lene to see problem
3030 const semaphore = new CountingSemaphore ( buffer , 0 , 10 ) ;
3131 console . dir ( { semaphore : semaphore . counter [ 0 ] } ) ;
3232 for ( let i = 0 ; i < 20 ; i ++ ) {
Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ class CountingSemaphore {
3636
3737if ( isMainThread ) {
3838 const buffer = new SharedArrayBuffer ( 4 ) ;
39+ // Try change 10 to 2 at next lene to check solution
3940 const semaphore = new CountingSemaphore ( buffer , 0 , 10 ) ;
4041 console . dir ( { semaphore : semaphore . counter [ 0 ] } ) ;
4142 for ( let i = 0 ; i < 20 ; i ++ ) {
Original file line number Diff line number Diff line change @@ -28,7 +28,8 @@ class CountingSemaphore {
2828
2929if ( isMainThread ) {
3030 const buffer = new SharedArrayBuffer ( 4 ) ;
31- const semaphore = new CountingSemaphore ( buffer , 0 , 2 ) ;
31+ // Try change 10 to 2 at next lene to check solution
32+ const semaphore = new CountingSemaphore ( buffer , 0 , 10 ) ;
3233 console . dir ( { semaphore : semaphore . counter [ 0 ] } ) ;
3334 for ( let i = 0 ; i < 20 ; i ++ ) {
3435 new Worker ( __filename , { workerData : buffer } ) ;
You can’t perform that action at this time.
0 commit comments