Skip to content

Commit ff321da

Browse files
committed
Address Copilot's review comments
Fix lambda reference capture bug where all threads processed the last disk's stripes instead of their own; fix shared 0xdeadbeef EThread* sentinel by using a thread_local variable to give each OS thread a unique identity for MUTEX_TAKE_LOCK.
1 parent c1618e8 commit ff321da

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

src/iocore/cache/CacheDir.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -981,8 +981,11 @@ sync_cache_dir_on_shutdown()
981981
threads.reserve(drive_stripe_map.size());
982982
for (auto &[disk, indices] : drive_stripe_map) {
983983
Dbg(dbg_ctl_cache_dir_sync, "Disk %s: syncing %zu stripe(s)", disk->path, indices.size());
984-
threads.emplace_back([&indices]() {
985-
EThread *t = reinterpret_cast<EThread *>(0xdeadbeef);
984+
threads.emplace_back([indices]() {
985+
// Use a thread_local variable to give each OS thread a unique EThread* sentinel,
986+
// satisfying MUTEX_TAKE_LOCK's thread_holding check without a real EThread.
987+
thread_local char thread_sentinel;
988+
EThread *t = reinterpret_cast<EThread *>(&thread_sentinel);
986989

987990
for (int idx : indices) {
988991
gstripes[idx]->shutdown(t);

0 commit comments

Comments
 (0)