Skip to content

Commit

Permalink
Note.
Browse files Browse the repository at this point in the history
  • Loading branch information
trivialfis committed Jun 27, 2024
1 parent a488e75 commit 21a301c
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/c_api/coll_c_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,18 @@ XGB_DLL int XGTrackerFree(TrackerHandle handle) {
common::Timer timer;
timer.Start();
// Make sure no one else is waiting on the tracker.

// Quote from https://en.cppreference.com/w/cpp/memory/shared_ptr/use_count#Notes:
//
// In multithreaded environment, `use_count() == 1` does not imply that the object is
// safe to modify because accesses to the managed object by former shared owners may not
// have completed, and because new shared owners may be introduced concurrently.
//
// - We don't have the first case since we never access the raw pointer.
//
// - We don't hve the second case for most of the scenarios since tracker is an unique
// object, if the free function is called before another function calls, it's likely
// to be a bug in the user code. The use_count should only decrease in this function.
while (ptr->first.use_count() != 1) {
auto ela = timer.Duration().count();
if (collective::HasTimeout(ptr->first->Timeout()) && ela > ptr->first->Timeout().count()) {
Expand Down

0 comments on commit 21a301c

Please sign in to comment.