cs-concurrency
Concurrency: threads vs async, locks/mutexes/rwlocks, atomics, lock-free, actor model, STM, deadlock
What this skill does
# cs-concurrency
## Purpose
This skill equips OpenClaw to assist with concurrency concepts in computer science, including threads vs. async programming, synchronization primitives like locks and atomics, and advanced topics like actor models, STM, and deadlock avoidance. Use it to generate code, explain pitfalls, or debug issues.
## When to Use
Apply this skill when developing multi-threaded applications (e.g., in C++ or Python), handling shared resources to prevent race conditions, optimizing for I/O-bound tasks with async/await, or analyzing deadlocks in production code. Use it for real-time systems, web servers, or distributed computing where concurrency is critical.
## Key Capabilities
- Explain differences: Threads (blocking, OS-level) vs. async (non-blocking, event-loop based).
- Demonstrate synchronization: Implement mutexes, RW locks, and atomics for shared data.
- Handle advanced patterns: Generate actor model code (e.g., using Erlang-style actors) or STM for transactional memory.
- Detect issues: Identify potential deadlocks or race conditions in provided code snippets.
- Optimize: Suggest lock-free data structures like concurrent queues.
## Usage Patterns
Invoke OpenClaw via CLI for quick explanations or code generation; use API for integration into scripts. Always specify the subtopic (e.g., "threads" or "locks") for targeted responses. For interactive sessions, prefix commands with "openclaw cs-concurrency". If using programmatically, pass JSON payloads with required parameters like topic and language.
## Common Commands/API
Use CLI commands like:
`openclaw cs-concurrency explain threads --lang python` (explains threads with a Python example).
`openclaw cs-concurrency generate lock --type mutex --code c++` (generates a mutex example in C++).
For API, send POST requests to `/api/cs-concurrency/explain` with JSON body:
`{ "topic": "atomics", "lang": "rust", "detail": "high" }`
Headers: `Authorization: Bearer $OPENCLAW_API_KEY` (set via environment variable for authentication).
Config format for custom sessions:
JSON file like `{ "defaultLang": "go", "focus": ["deadlock", "async"] }` passed with `--config path/to/file.json`.
## Integration Notes
Integrate by setting $OPENCLAW_API_KEY in your environment for authenticated API calls. For example, in a bash script: `export OPENCLAW_API_KEY=your_api_key_here`. Combine with other tools like debuggers (e.g., gdb for threads) by piping output: `openclaw cs-concurrency explain deadlock | gdb -ex "run"`. Ensure your application handles async contexts if embedding responses in Node.js or Python event loops.
## Error Handling
When using this skill, check for concurrency errors like deadlocks by wrapping code in try-except blocks. For example, in Python:
```python
import threading
lock = threading.Lock()
try:
with lock:
# Critical section
pass
except threading.LockError:
print("Lock acquisition failed")
```
For API calls, handle HTTP errors (e.g., 401 for invalid $OPENCLAW_API_KEY) by checking response status codes. In OpenClaw commands, use `--verbose` flag to debug: `openclaw cs-concurrency explain async --verbose` to log detailed errors.
## Concrete Usage Examples
**Example 1:** To generate a simple threads example in C++:
Run: `openclaw cs-concurrency generate threads --lang c++`
Output might include:
```cpp
#include <thread>
void task() { /* code */ }
int main() {
std::thread t1(task);
t1.join();
}
```
This helps in understanding basic thread creation and joining.
**Example 2:** To explain and fix a race condition with atomics:
Command: `openclaw cs-concurrency explain race --fix --lang rust`
Response: Explains the issue and provides:
```rust
use std::sync::atomic::{AtomicUsize, Ordering};
static COUNTER: AtomicUsize = AtomicUsize::new(0);
COUNTER.fetch_add(1, Ordering::SeqCst);
```
Use this to safely increment shared counters without locks.
## Graph Relationships
- Related to: cs-algorithms (via concurrency tag for parallel algorithms)
- Connected to: programming-languages (shares tags like "threads" for language-specific implementations)
- Links with: software-engineering (for deadlock in system design)
- Associated via: cs (cluster overlap for computer science topics)
Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.