1 /*
   2  * Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "memory/allocation.hpp"
  27 #include "memory/allocation.inline.hpp"
  28 #include "runtime/atomic.inline.hpp"
  29 #include "runtime/os.hpp"
  30 #include "utilities/workgroup.hpp"
  31 
  32 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
  33 
  34 // Definitions of WorkGang methods.
  35 
  36 AbstractWorkGang::AbstractWorkGang(const char* name,
  37                                    bool  are_GC_task_threads,
  38                                    bool  are_ConcurrentGC_threads) :
  39   _name(name),
  40   _are_GC_task_threads(are_GC_task_threads),
  41   _are_ConcurrentGC_threads(are_ConcurrentGC_threads) {
  42 
  43   assert(!(are_GC_task_threads && are_ConcurrentGC_threads),
  44          "They cannot both be STW GC and Concurrent threads" );
  45 
  46   // Other initialization.
  47   _monitor = new Monitor(/* priority */       Mutex::leaf,
  48                          /* name */           "WorkGroup monitor",
  49                          /* allow_vm_block */ are_GC_task_threads,
  50                                               Monitor::_safepoint_check_sometimes);
  51   assert(monitor() != NULL, "Failed to allocate monitor");
  52   _terminate = false;
  53   _task = NULL;
  54   _sequence_number = 0;
  55   _started_workers = 0;
  56   _finished_workers = 0;
  57 }
  58 
  59 WorkGang::WorkGang(const char* name,
  60                    uint        workers,
  61                    bool        are_GC_task_threads,
  62                    bool        are_ConcurrentGC_threads) :
  63   AbstractWorkGang(name, are_GC_task_threads, are_ConcurrentGC_threads) {
  64   _total_workers = workers;
  65 }
  66 
  67 GangWorker* WorkGang::allocate_worker(uint which) {
  68   GangWorker* new_worker = new GangWorker(this, which);
  69   return new_worker;
  70 }
  71 
  72 // The current implementation will exit if the allocation
  73 // of any worker fails.  Still, return a boolean so that
  74 // a future implementation can possibly do a partial
  75 // initialization of the workers and report such to the
  76 // caller.
  77 bool WorkGang::initialize_workers() {
  78 
  79   if (TraceWorkGang) {
  80     tty->print_cr("Constructing work gang %s with %d threads",
  81                   name(),
  82                   total_workers());
  83   }
  84   _gang_workers = NEW_C_HEAP_ARRAY(GangWorker*, total_workers(), mtInternal);
  85   if (gang_workers() == NULL) {
  86     vm_exit_out_of_memory(0, OOM_MALLOC_ERROR, "Cannot create GangWorker array.");
  87     return false;
  88   }
  89   os::ThreadType worker_type;
  90   if (are_ConcurrentGC_threads()) {
  91     worker_type = os::cgc_thread;
  92   } else {
  93     worker_type = os::pgc_thread;
  94   }
  95   for (uint worker = 0; worker < total_workers(); worker += 1) {
  96     GangWorker* new_worker = allocate_worker(worker);
  97     assert(new_worker != NULL, "Failed to allocate GangWorker");
  98     _gang_workers[worker] = new_worker;
  99     if (new_worker == NULL || !os::create_thread(new_worker, worker_type)) {
 100       vm_exit_out_of_memory(0, OOM_MALLOC_ERROR,
 101               "Cannot create worker GC thread. Out of system resources.");
 102       return false;
 103     }
 104     if (!DisableStartThread) {
 105       os::start_thread(new_worker);
 106     }
 107   }
 108   return true;
 109 }
 110 
 111 AbstractWorkGang::~AbstractWorkGang() {
 112   if (TraceWorkGang) {
 113     tty->print_cr("Destructing work gang %s", name());
 114   }
 115   stop();   // stop all the workers
 116   for (uint worker = 0; worker < total_workers(); worker += 1) {
 117     delete gang_worker(worker);
 118   }
 119   delete gang_workers();
 120   delete monitor();
 121 }
 122 
 123 GangWorker* AbstractWorkGang::gang_worker(uint i) const {
 124   // Array index bounds checking.
 125   GangWorker* result = NULL;
 126   assert(gang_workers() != NULL, "No workers for indexing");
 127   assert(i < total_workers(), "Worker index out of bounds");
 128   result = _gang_workers[i];
 129   assert(result != NULL, "Indexing to null worker");
 130   return result;
 131 }
 132 
 133 void WorkGang::run_task(AbstractGangTask* task) {
 134   run_task(task, total_workers());
 135 }
 136 
 137 void WorkGang::run_task(AbstractGangTask* task, uint no_of_parallel_workers) {
 138   task->set_for_termination(no_of_parallel_workers);
 139 
 140   // This thread is executed by the VM thread which does not block
 141   // on ordinary MutexLocker's.
 142   MutexLockerEx ml(monitor(), Mutex::_no_safepoint_check_flag);
 143   if (TraceWorkGang) {
 144     tty->print_cr("Running work gang %s task %s", name(), task->name());
 145   }
 146   // Tell all the workers to run a task.
 147   assert(task != NULL, "Running a null task");
 148   // Initialize.
 149   _task = task;
 150   _sequence_number += 1;
 151   _started_workers = 0;
 152   _finished_workers = 0;
 153   // Tell the workers to get to work.
 154   monitor()->notify_all();
 155   // Wait for them to be finished
 156   while (finished_workers() < no_of_parallel_workers) {
 157     if (TraceWorkGang) {
 158       tty->print_cr("Waiting in work gang %s: %d/%d finished sequence %d",
 159                     name(), finished_workers(), no_of_parallel_workers,
 160                     _sequence_number);
 161     }
 162     monitor()->wait(/* no_safepoint_check */ true);
 163   }
 164   _task = NULL;
 165   if (TraceWorkGang) {
 166     tty->print_cr("\nFinished work gang %s: %d/%d sequence %d",
 167                   name(), finished_workers(), no_of_parallel_workers,
 168                   _sequence_number);
 169     Thread* me = Thread::current();
 170     tty->print_cr("  T: 0x%x  VM_thread: %d", me, me->is_VM_thread());
 171   }
 172 }
 173 
 174 void FlexibleWorkGang::run_task(AbstractGangTask* task) {
 175   // If active_workers() is passed, _finished_workers
 176   // must only be incremented for workers that find non_null
 177   // work (as opposed to all those that just check that the
 178   // task is not null).
 179   WorkGang::run_task(task, (uint) active_workers());
 180 }
 181 
 182 void AbstractWorkGang::stop() {
 183   // Tell all workers to terminate, then wait for them to become inactive.
 184   MutexLockerEx ml(monitor(), Mutex::_no_safepoint_check_flag);
 185   if (TraceWorkGang) {
 186     tty->print_cr("Stopping work gang %s task %s", name(), task()->name());
 187   }
 188   _task = NULL;
 189   _terminate = true;
 190   monitor()->notify_all();
 191   while (finished_workers() < active_workers()) {
 192     if (TraceWorkGang) {
 193       tty->print_cr("Waiting in work gang %s: %d/%d finished",
 194                     name(), finished_workers(), active_workers());
 195     }
 196     monitor()->wait(/* no_safepoint_check */ true);
 197   }
 198 }
 199 
 200 void AbstractWorkGang::internal_worker_poll(WorkData* data) const {
 201   assert(monitor()->owned_by_self(), "worker_poll is an internal method");
 202   assert(data != NULL, "worker data is null");
 203   data->set_terminate(terminate());
 204   data->set_task(task());
 205   data->set_sequence_number(sequence_number());
 206 }
 207 
 208 void AbstractWorkGang::internal_note_start() {
 209   assert(monitor()->owned_by_self(), "note_finish is an internal method");
 210   _started_workers += 1;
 211 }
 212 
 213 void AbstractWorkGang::internal_note_finish() {
 214   assert(monitor()->owned_by_self(), "note_finish is an internal method");
 215   _finished_workers += 1;
 216 }
 217 
 218 void AbstractWorkGang::print_worker_threads_on(outputStream* st) const {
 219   uint    num_thr = total_workers();
 220   for (uint i = 0; i < num_thr; i++) {
 221     gang_worker(i)->print_on(st);
 222     st->cr();
 223   }
 224 }
 225 
 226 void AbstractWorkGang::threads_do(ThreadClosure* tc) const {
 227   assert(tc != NULL, "Null ThreadClosure");
 228   uint num_thr = total_workers();
 229   for (uint i = 0; i < num_thr; i++) {
 230     tc->do_thread(gang_worker(i));
 231   }
 232 }
 233 
 234 // GangWorker methods.
 235 
 236 GangWorker::GangWorker(AbstractWorkGang* gang, uint id) {
 237   _gang = gang;
 238   set_id(id);
 239   set_name("%s#%d", gang->name(), id);
 240 }
 241 
 242 void GangWorker::run() {
 243   initialize();
 244   loop();
 245 }
 246 
 247 void GangWorker::initialize() {
 248   this->initialize_thread_local_storage();
 249   this->record_stack_base_and_size();
 250   this->initialize_named_thread();
 251   assert(_gang != NULL, "No gang to run in");
 252   os::set_priority(this, NearMaxPriority);
 253   if (TraceWorkGang) {
 254     tty->print_cr("Running gang worker for gang %s id %d",
 255                   gang()->name(), id());
 256   }
 257   // The VM thread should not execute here because MutexLocker's are used
 258   // as (opposed to MutexLockerEx's).
 259   assert(!Thread::current()->is_VM_thread(), "VM thread should not be part"
 260          " of a work gang");
 261 }
 262 
 263 void GangWorker::loop() {
 264   int previous_sequence_number = 0;
 265   Monitor* gang_monitor = gang()->monitor();
 266   for ( ; /* !terminate() */; ) {
 267     WorkData data;
 268     int part;  // Initialized below.
 269     {
 270       // Grab the gang mutex.
 271       MutexLocker ml(gang_monitor);
 272       // Wait for something to do.
 273       // Polling outside the while { wait } avoids missed notifies
 274       // in the outer loop.
 275       gang()->internal_worker_poll(&data);
 276       if (TraceWorkGang) {
 277         tty->print("Polled outside for work in gang %s worker %d",
 278                    gang()->name(), id());
 279         tty->print("  terminate: %s",
 280                    data.terminate() ? "true" : "false");
 281         tty->print("  sequence: %d (prev: %d)",
 282                    data.sequence_number(), previous_sequence_number);
 283         if (data.task() != NULL) {
 284           tty->print("  task: %s", data.task()->name());
 285         } else {
 286           tty->print("  task: NULL");
 287         }
 288         tty->cr();
 289       }
 290       for ( ; /* break or return */; ) {
 291         // Terminate if requested.
 292         if (data.terminate()) {
 293           gang()->internal_note_finish();
 294           gang_monitor->notify_all();
 295           return;
 296         }
 297         // Check for new work.
 298         if ((data.task() != NULL) &&
 299             (data.sequence_number() != previous_sequence_number)) {
 300           if (gang()->needs_more_workers()) {
 301             gang()->internal_note_start();
 302             gang_monitor->notify_all();
 303             part = gang()->started_workers() - 1;
 304             break;
 305           }
 306         }
 307         // Nothing to do.
 308         gang_monitor->wait(/* no_safepoint_check */ true);
 309         gang()->internal_worker_poll(&data);
 310         if (TraceWorkGang) {
 311           tty->print("Polled inside for work in gang %s worker %d",
 312                      gang()->name(), id());
 313           tty->print("  terminate: %s",
 314                      data.terminate() ? "true" : "false");
 315           tty->print("  sequence: %d (prev: %d)",
 316                      data.sequence_number(), previous_sequence_number);
 317           if (data.task() != NULL) {
 318             tty->print("  task: %s", data.task()->name());
 319           } else {
 320             tty->print("  task: NULL");
 321           }
 322           tty->cr();
 323         }
 324       }
 325       // Drop gang mutex.
 326     }
 327     if (TraceWorkGang) {
 328       tty->print("Work for work gang %s id %d task %s part %d",
 329                  gang()->name(), id(), data.task()->name(), part);
 330     }
 331     assert(data.task() != NULL, "Got null task");
 332     data.task()->work(part);
 333     {
 334       if (TraceWorkGang) {
 335         tty->print("Finish for work gang %s id %d task %s part %d",
 336                    gang()->name(), id(), data.task()->name(), part);
 337       }
 338       // Grab the gang mutex.
 339       MutexLocker ml(gang_monitor);
 340       gang()->internal_note_finish();
 341       // Tell the gang you are done.
 342       gang_monitor->notify_all();
 343       // Drop the gang mutex.
 344     }
 345     previous_sequence_number = data.sequence_number();
 346   }
 347 }
 348 
 349 bool GangWorker::is_GC_task_thread() const {
 350   return gang()->are_GC_task_threads();
 351 }
 352 
 353 bool GangWorker::is_ConcurrentGC_thread() const {
 354   return gang()->are_ConcurrentGC_threads();
 355 }
 356 
 357 void GangWorker::print_on(outputStream* st) const {
 358   st->print("\"%s\" ", name());
 359   Thread::print_on(st);
 360   st->cr();
 361 }
 362 
 363 // Printing methods
 364 
 365 const char* AbstractWorkGang::name() const {
 366   return _name;
 367 }
 368 
 369 #ifndef PRODUCT
 370 
 371 const char* AbstractGangTask::name() const {
 372   return _name;
 373 }
 374 
 375 #endif /* PRODUCT */
 376 
 377 // FlexibleWorkGang
 378 
 379 
 380 // *** WorkGangBarrierSync
 381 
 382 WorkGangBarrierSync::WorkGangBarrierSync()
 383   : _monitor(Mutex::safepoint, "work gang barrier sync", true,
 384              Monitor::_safepoint_check_never),
 385     _n_workers(0), _n_completed(0), _should_reset(false), _aborted(false) {
 386 }
 387 
 388 WorkGangBarrierSync::WorkGangBarrierSync(uint n_workers, const char* name)
 389   : _monitor(Mutex::safepoint, name, true, Monitor::_safepoint_check_never),
 390     _n_workers(n_workers), _n_completed(0), _should_reset(false), _aborted(false) {
 391 }
 392 
 393 void WorkGangBarrierSync::set_n_workers(uint n_workers) {
 394   _n_workers    = n_workers;
 395   _n_completed  = 0;
 396   _should_reset = false;
 397   _aborted      = false;
 398 }
 399 
 400 bool WorkGangBarrierSync::enter() {
 401   MutexLockerEx x(monitor(), Mutex::_no_safepoint_check_flag);
 402   if (should_reset()) {
 403     // The should_reset() was set and we are the first worker to enter
 404     // the sync barrier. We will zero the n_completed() count which
 405     // effectively resets the barrier.
 406     zero_completed();
 407     set_should_reset(false);
 408   }
 409   inc_completed();
 410   if (n_completed() == n_workers()) {
 411     // At this point we would like to reset the barrier to be ready in
 412     // case it is used again. However, we cannot set n_completed() to
 413     // 0, even after the notify_all(), given that some other workers
 414     // might still be waiting for n_completed() to become ==
 415     // n_workers(). So, if we set n_completed() to 0, those workers
 416     // will get stuck (as they will wake up, see that n_completed() !=
 417     // n_workers() and go back to sleep). Instead, we raise the
 418     // should_reset() flag and the barrier will be reset the first
 419     // time a worker enters it again.
 420     set_should_reset(true);
 421     monitor()->notify_all();
 422   } else {
 423     while (n_completed() != n_workers() && !aborted()) {
 424       monitor()->wait(/* no_safepoint_check */ true);
 425     }
 426   }
 427   return !aborted();
 428 }
 429 
 430 void WorkGangBarrierSync::abort() {
 431   MutexLockerEx x(monitor(), Mutex::_no_safepoint_check_flag);
 432   set_aborted();
 433   monitor()->notify_all();
 434 }
 435 
 436 // SubTasksDone functions.
 437 
 438 SubTasksDone::SubTasksDone(uint n) :
 439   _n_tasks(n), _n_threads(1), _tasks(NULL) {
 440   _tasks = NEW_C_HEAP_ARRAY(uint, n, mtInternal);
 441   guarantee(_tasks != NULL, "alloc failure");
 442   clear();
 443 }
 444 
 445 bool SubTasksDone::valid() {
 446   return _tasks != NULL;
 447 }
 448 
 449 void SubTasksDone::set_n_threads(uint t) {
 450   assert(_claimed == 0 || _threads_completed == _n_threads,
 451          "should not be called while tasks are being processed!");
 452   _n_threads = (t == 0 ? 1 : t);
 453 }
 454 
 455 void SubTasksDone::clear() {
 456   for (uint i = 0; i < _n_tasks; i++) {
 457     _tasks[i] = 0;
 458   }
 459   _threads_completed = 0;
 460 #ifdef ASSERT
 461   _claimed = 0;
 462 #endif
 463 }
 464 
 465 bool SubTasksDone::is_task_claimed(uint t) {
 466   assert(t < _n_tasks, "bad task id.");
 467   uint old = _tasks[t];
 468   if (old == 0) {
 469     old = Atomic::cmpxchg(1, &_tasks[t], 0);
 470   }
 471   assert(_tasks[t] == 1, "What else?");
 472   bool res = old != 0;
 473 #ifdef ASSERT
 474   if (!res) {
 475     assert(_claimed < _n_tasks, "Too many tasks claimed; missing clear?");
 476     Atomic::inc((volatile jint*) &_claimed);
 477   }
 478 #endif
 479   return res;
 480 }
 481 
 482 void SubTasksDone::all_tasks_completed() {
 483   jint observed = _threads_completed;
 484   jint old;
 485   do {
 486     old = observed;
 487     observed = Atomic::cmpxchg(old+1, &_threads_completed, old);
 488   } while (observed != old);
 489   // If this was the last thread checking in, clear the tasks.
 490   if (observed+1 == (jint)_n_threads) clear();
 491 }
 492 
 493 
 494 SubTasksDone::~SubTasksDone() {
 495   if (_tasks != NULL) FREE_C_HEAP_ARRAY(jint, _tasks);
 496 }
 497 
 498 // *** SequentialSubTasksDone
 499 
 500 void SequentialSubTasksDone::clear() {
 501   _n_tasks   = _n_claimed   = 0;
 502   _n_threads = _n_completed = 0;
 503 }
 504 
 505 bool SequentialSubTasksDone::valid() {
 506   return _n_threads > 0;
 507 }
 508 
 509 bool SequentialSubTasksDone::is_task_claimed(uint& t) {
 510   uint* n_claimed_ptr = &_n_claimed;
 511   t = *n_claimed_ptr;
 512   while (t < _n_tasks) {
 513     jint res = Atomic::cmpxchg(t+1, n_claimed_ptr, t);
 514     if (res == (jint)t) {
 515       return false;
 516     }
 517     t = *n_claimed_ptr;
 518   }
 519   return true;
 520 }
 521 
 522 bool SequentialSubTasksDone::all_tasks_completed() {
 523   uint* n_completed_ptr = &_n_completed;
 524   uint  complete        = *n_completed_ptr;
 525   while (true) {
 526     uint res = Atomic::cmpxchg(complete+1, n_completed_ptr, complete);
 527     if (res == complete) {
 528       break;
 529     }
 530     complete = res;
 531   }
 532   if (complete+1 == _n_threads) {
 533     clear();
 534     return true;
 535   }
 536   return false;
 537 }
 538 
 539 bool FreeIdSet::_stat_init = false;
 540 FreeIdSet* FreeIdSet::_sets[NSets];
 541 bool FreeIdSet::_safepoint;
 542 
 543 FreeIdSet::FreeIdSet(int sz, Monitor* mon) :
 544   _sz(sz), _mon(mon), _hd(0), _waiters(0), _index(-1), _claimed(0)
 545 {
 546   _ids = NEW_C_HEAP_ARRAY(int, sz, mtInternal);
 547   for (int i = 0; i < sz; i++) _ids[i] = i+1;
 548   _ids[sz-1] = end_of_list; // end of list.
 549   if (_stat_init) {
 550     for (int j = 0; j < NSets; j++) _sets[j] = NULL;
 551     _stat_init = true;
 552   }
 553   // Add to sets.  (This should happen while the system is still single-threaded.)
 554   for (int j = 0; j < NSets; j++) {
 555     if (_sets[j] == NULL) {
 556       _sets[j] = this;
 557       _index = j;
 558       break;
 559     }
 560   }
 561   guarantee(_index != -1, "Too many FreeIdSets in use!");
 562 }
 563 
 564 FreeIdSet::~FreeIdSet() {
 565   _sets[_index] = NULL;
 566   FREE_C_HEAP_ARRAY(int, _ids);
 567 }
 568 
 569 void FreeIdSet::set_safepoint(bool b) {
 570   _safepoint = b;
 571   if (b) {
 572     for (int j = 0; j < NSets; j++) {
 573       if (_sets[j] != NULL && _sets[j]->_waiters > 0) {
 574         Monitor* mon = _sets[j]->_mon;
 575         mon->lock_without_safepoint_check();
 576         mon->notify_all();
 577         mon->unlock();
 578       }
 579     }
 580   }
 581 }
 582 
 583 #define FID_STATS 0
 584 
 585 int FreeIdSet::claim_par_id() {
 586 #if FID_STATS
 587   thread_t tslf = thr_self();
 588   tty->print("claim_par_id[%d]: sz = %d, claimed = %d\n", tslf, _sz, _claimed);
 589 #endif
 590   MutexLockerEx x(_mon, Mutex::_no_safepoint_check_flag);
 591   while (!_safepoint && _hd == end_of_list) {
 592     _waiters++;
 593 #if FID_STATS
 594     if (_waiters > 5) {
 595       tty->print("claim_par_id waiting[%d]: %d waiters, %d claimed.\n",
 596                  tslf, _waiters, _claimed);
 597     }
 598 #endif
 599     _mon->wait(Mutex::_no_safepoint_check_flag);
 600     _waiters--;
 601   }
 602   if (_hd == end_of_list) {
 603 #if FID_STATS
 604     tty->print("claim_par_id[%d]: returning EOL.\n", tslf);
 605 #endif
 606     return -1;
 607   } else {
 608     int res = _hd;
 609     _hd = _ids[res];
 610     _ids[res] = claimed;  // For debugging.
 611     _claimed++;
 612 #if FID_STATS
 613     tty->print("claim_par_id[%d]: returning %d, claimed = %d.\n",
 614                tslf, res, _claimed);
 615 #endif
 616     return res;
 617   }
 618 }
 619 
 620 bool FreeIdSet::claim_perm_id(int i) {
 621   assert(0 <= i && i < _sz, "Out of range.");
 622   MutexLockerEx x(_mon, Mutex::_no_safepoint_check_flag);
 623   int prev = end_of_list;
 624   int cur = _hd;
 625   while (cur != end_of_list) {
 626     if (cur == i) {
 627       if (prev == end_of_list) {
 628         _hd = _ids[cur];
 629       } else {
 630         _ids[prev] = _ids[cur];
 631       }
 632       _ids[cur] = claimed;
 633       _claimed++;
 634       return true;
 635     } else {
 636       prev = cur;
 637       cur = _ids[cur];
 638     }
 639   }
 640   return false;
 641 
 642 }
 643 
 644 void FreeIdSet::release_par_id(int id) {
 645   MutexLockerEx x(_mon, Mutex::_no_safepoint_check_flag);
 646   assert(_ids[id] == claimed, "Precondition.");
 647   _ids[id] = _hd;
 648   _hd = id;
 649   _claimed--;
 650 #if FID_STATS
 651   tty->print("[%d] release_par_id(%d), waiters =%d,  claimed = %d.\n",
 652              thr_self(), id, _waiters, _claimed);
 653 #endif
 654   if (_waiters > 0)
 655     // Notify all would be safer, but this is OK, right?
 656     _mon->notify_all();
 657 }