Skip to content

Commit 3cfb438

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 3cfb438

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

src/iocore/cache/CacheDir.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -981,10 +981,13 @@ 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+
auto stripe_indices = indices;
985+
threads.emplace_back([stripe_indices]() {
986+
// Use a thread_local variable to give each OS thread a unique EThread* sentinel instead of 0xdeadbeef.
987+
thread_local char thread_sentinel;
988+
EThread *t = reinterpret_cast<EThread *>(&thread_sentinel);
986989

987-
for (int idx : indices) {
990+
for (int idx : stripe_indices) {
988991
gstripes[idx]->shutdown(t);
989992
}
990993
});

0 commit comments

Comments
 (0)