Skip to content

Isurwars/Correlation / .agents/skills/concurrency

concurrency

Verified

Enforce thread-safety rules for OpenMP and TBB loops, std::scoped_lock synchronization, atomic state management, and cache alignment in parallel structural calculators. Use when writing, debugging, or profiling multi-threaded algorithms.

Concurrency & Parallel Patterns

This skill governs multi-threaded execution, OpenMP/TBB safety rules, and lock-free memory locality across Correlation calculators (RDF, S(Q), PAD, VACF, MSD).

1. OpenMP Loop Safety Rules

Rule 1: Thread-Private Iterators

Loop variables inside #pragma omp parallel for constructs must be thread-private. Never share loop indices across threads.

// GOOD: OpenMP thread-private loop bounds
#pragma omp parallel for schedule(dynamic)
for (int i = 0; i < num_atoms; ++i) {
    for (int j = i + 1; j < num_atoms; ++j) {
        // Distance calculation
    }
}

Rule 2: Cache-Line Alignment (alignas(64))

Eliminate false sharing by padding thread-local accumulators to 64-byte cache lines:

struct alignas(64) ThreadLocalHistogram {
    std::vector<uint64_t> bins;
};

2. Synchronization Primitives

Rule 1: Safe Mutex Locking (std::scoped_lock)

Always use std::scoped_lock for locking one or more mutexes (C++17 RAII deadlock-free locking). Avoid raw .lock() / .unlock().

#include <mutex>

void update_shared_state(SharedData& data1, SharedData& data2) {
    std::scoped_lock lock(data1.mutex, data2.mutex);
    // Deadlock-safe multi-mutex mutation
}

Rule 2: Thread-Safe Async Slint Dispatch

Background worker threads MUST dispatch UI progress updates using slint::invoke_from_event_loop(), and threads must be managed via RAII (std::jthread):

#include <slint/slint.h>
#include <thread>

std::jthread calculate_async(slint::ComponentHandle<AppWindow> window) {
    return std::jthread([window](std::stop_token stop_token) {
        // Parallel computation loop
        #pragma omp parallel for
        for (int i = 0; i < total; ++i) {
            if (stop_token.stop_requested()) break;
            /* ... */
        }

        // Async UI update
        slint::invoke_from_event_loop([window]() {
            window->set_progress(1.0f);
        });
    });
}

3. Concurrency Anti-Patterns

  • ❌ Modifying shared std::vector inside OpenMP loops without thread-local buffers or mutexes (data race).
  • ❌ Using std::endl or raw std::cout inside parallel loops (interleaved IO streams).
  • ❌ Omitting alignas(64) on thread-local reduction arrays (false sharing cache degradation).
  • ❌ Using std::thread::detach() with unmanaged raw pointers or uncoordinated lifetimes.
slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack."Stars: 197kUpdated Claude CodeCodexVerifiedInstall
ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt.Stars: 194kUpdated Claude CodeCodexVerifiedInstall