@@ -41,7 +41,7 @@ export class Scheduler implements SchedulerInterface {
4141 __funloop : Thread [ ] ;
4242
4343 /** Queue of blocked threads. */
44- __blocked : Thread [ ] ;
44+ __blocked : { [ tid in string ] : Thread } ;
4545
4646 /** Map of alive threads from their stringified identifier, `tid`. */
4747 __alive : { [ tid in string ] : Thread } ;
@@ -64,7 +64,7 @@ export class Scheduler implements SchedulerInterface {
6464 this . rt_uuid = runId ;
6565 this . rtObj = rtObj ;
6666 this . __funloop = [ ] ;
67- this . __blocked = [ ] ;
67+ this . __blocked = { } ;
6868 this . __alive = { } ;
6969 this . __currentThread = null ;
7070 }
@@ -90,7 +90,7 @@ export class Scheduler implements SchedulerInterface {
9090 delete this . __alive [ x ] ;
9191 }
9292 }
93- this . __blocked = [ ] ;
93+ this . __blocked = { } ;
9494 this . __funloop = [ ] ;
9595 // console.log (`The number of active threads is ${Object.keys(this.__alive).length}`)
9696 // console.log (`The number of blocked threads is ${this.__blocked.length}`)
@@ -160,18 +160,15 @@ export class Scheduler implements SchedulerInterface {
160160
161161 /** Block thread object `t`. */
162162 blockThread ( t : Thread ) {
163- this . __blocked . push ( t ) ;
163+ this . __blocked [ t . tid . val . toString ( ) ] = t ;
164164 }
165165
166166 /** Unblock the thread with the given identifier, `pid`. */
167167 unblockThread ( tid : LVal ) {
168- for ( let i = 0 ; i < this . __blocked . length ; i ++ ) {
169- if ( pid_equals ( this . __blocked [ i ] . tid , tid ) ) {
170- this . scheduleThread ( this . __blocked [ i ] ) ;
171- this . __blocked . splice ( i , 1 ) ;
172- break ;
173- }
174- }
168+ if ( ! this . __blocked [ tid . val . toString ( ) ] ) { return ; }
169+
170+ this . scheduleThread ( this . __blocked [ tid . val . toString ( ) ] ) ;
171+ delete this . __blocked [ tid . val . toString ( ) ] ;
175172 }
176173
177174 /*************************************************************************************************\
0 commit comments