Changeset c5bbb9b
- Timestamp:
- Nov 5, 2020, 3:33:28 PM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- f4e35326
- Parents:
- eeb5023
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/locks.cfa
reeb5023 rc5bbb9b 236 236 forall(dtype L | is_blocking_lock(L)) { 237 237 238 void timeout_handler ( condition_variable(L) * cond , info_thread(L) ** i) {238 void timeout_handler ( alarm_node_wrap(L) & this ) with( this ) { 239 239 // This condition_variable member is called from the kernel, and therefore, cannot block, but it can spin. 240 240 lock( cond->lock __cfaabi_dbg_ctx2 ); … … 242 242 info_thread(L) * copy = *i; 243 243 remove( cond->blocked_threads, i ); //remove this thread O(1) 244 cond->wait_count--; 244 245 if( !copy->lock ) { 245 246 unlock( cond->lock ); 246 printf("here");247 247 #if !defined( __CFA_NO_STATISTICS__ ) 248 248 kernelTLS.this_stats = copy->t->curr_cluster->stats; 249 249 #endif 250 250 unpark( copy->t ); 251 printf("here2");252 251 } else { 253 252 add_(*copy->lock, copy->t); // call lock's add_ … … 257 256 } 258 257 259 void alarm_node_callback( alarm_node_wrap(L) & this ) with( this ) {260 timeout_handler(cond, i);261 }262 263 258 void alarm_node_wrap_cast( alarm_node_t & a ) { 264 alarm_node_callback( (alarm_node_wrap(L) &)a );259 timeout_handler( (alarm_node_wrap(L) &)a ); 265 260 } 266 261 … … 289 284 popped->listed = false; 290 285 if(popped != 0p) { 291 add_(*popped->lock, popped->t);292 286 count--; 287 if (popped->lock) { 288 add_(*popped->lock, popped->t); 289 } else { 290 unpark(popped->t); 291 } 293 292 } 294 293 unlock( lock ); … … 303 302 popped->listed = false; 304 303 if(popped != 0p){ 305 add_(*popped->lock, popped->t);306 304 count--; 305 if (popped->lock) { 306 add_(*popped->lock, popped->t); 307 } else { 308 unpark(popped->t); 309 } 307 310 } 308 311 } … … 436 439 } 437 440 } 438 439 thread T1 {};440 thread T2 {};441 442 recursive_mutex_lock m;443 condition_variable( recursive_mutex_lock ) c;444 445 void main( T1 & this ) {446 printf("T1 start\n");447 lock(m);448 printf("%d\n", counter(c));449 if(empty(c)) {450 printf("T1 wait\n");451 wait(c,m,12);452 }else{453 printf("%d\n", front(c));454 notify_one(c);455 }456 unlock(m);457 printf("curr thd in main %p \n", kernelTLS.this_thread);458 printf("T1 waits for 2s\n");459 lock(m);460 wait( c, m, 2`s );461 unlock(m);462 printf("T1 wakes\n");463 printf("T1 done\n");464 }465 466 void main( T2 & this ) {467 printf("T2 start\n");468 lock(m);469 printf("%d\n", counter(c));470 if(empty(c)) {471 printf("T2 wait\n");472 wait(c,m,12);473 }else{474 printf("%d\n", front(c));475 notify_one(c);476 }477 unlock(m);478 printf("T2 done\n");479 }480 481 int main() {482 printf("start\n");483 processor p[2];484 {485 T1 t1;486 T2 t2;487 }488 printf("done\n");489 }
Note: See TracChangeset
for help on using the changeset viewer.