Skip to content

Conversation

@unbalancedparentheses
Copy link

Summary

  • Add Pid struct with unique process identifiers and Erlang-style display format <0.N>
  • Add HasPid trait for types that have a process identifier
  • Add Link module with MonitorRef and SystemMessage for process linking/monitoring
  • Add ProcessTable for global process management, linking, and monitoring
  • Add Registry for name-based process lookup (like Erlang's register/2)

Features

  • Pid: Unique process identifiers with atomic counter, Hash/Eq for HashMap keys
  • ProcessTable: Thread-safe global table with link/monitor/trap_exit support
  • Registry: Name-based lookup with register, unregister, whereis, registered

Changes

  • concurrency/src/pid.rs - Pid struct and HasPid trait (~200 lines)
  • concurrency/src/link.rs - MonitorRef and SystemMessage (~180 lines)
  • concurrency/src/process_table.rs - Global process table (~490 lines)
  • concurrency/src/registry.rs - Process registry (~370 lines)
  • concurrency/src/lib.rs - Export new modules

Depends on: PR #107 (flatten module structure)

Test plan

  • Unit tests included in each module
  • Tests for Pid uniqueness and display format
  • Tests for process table link/monitor operations
  • Tests for registry register/unregister/whereis

🤖 Generated with Claude Code

unbalancedparentheses and others added 7 commits January 9, 2026 20:39
Consolidate the two separate GenServer implementations (async/tokio and
threads) into a single implementation with a Backend enum parameter.
Breaking change: start() now requires a Backend argument:
- Backend::Async - tokio async tasks (default)
- Backend::Blocking - tokio's blocking thread pool
- Backend::Thread - dedicated OS thread
This provides runtime flexibility without code duplication, allowing
users to mix different execution backends in the same application.
- Add Backend enum to gen_server.rs
- Change start() signature to accept Backend parameter
- Update all examples and tests
- Remove thread-based example crates
Add 10 new tests covering:
- Backend enum traits (Default, Copy, Clone, Debug, PartialEq, Eq)
- All three backends handle call/cast correctly
- Backend::Thread isolates blocking work from async runtime
- Multiple backends can run concurrently with independent state
- Backend::default() works in start()
Document each backend option with:
- Comparison table showing execution model, best use cases, and limitations
- Code examples for each backend
- Detailed "When to Use" guide with advantages and avoid-when advice
- Per-variant documentation with specific use cases
Move files from tasks/ to root and remove threads/ directory:
- concurrency/src/tasks/* → concurrency/src/*
- Delete concurrency/src/threads/ (replaced by Backend enum)
- Update all imports from spawned_concurrency::tasks:: to spawned_concurrency::

The Backend enum (Async, Blocking, Thread) now provides all the
functionality previously split between tasks and threads modules,
offering a cleaner and more unified API.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add Pid struct with unique process identifiers (AtomicU64)
- Add HasPid trait for types that have a process ID
- Add ExitReason enum (Normal, Shutdown, Error, Killed)
- Add MonitorRef for tracking monitors
- Add SystemMessage enum (Down, Exit, Timeout)

These are the foundational types for OTP-style process management.
- Add ProcessTable with global process tracking
- Implement bidirectional linking (link/unlink)
- Implement unidirectional monitoring (monitor/demonitor)
- Add trap_exit support for catching linked process exits
- Add SystemMessageSender trait for delivering DOWN/EXIT messages
- Handle exit propagation to linked processes

The process table is the central registry for all running processes
and manages the relationships between them.
- Add global Registry for name -> Pid mapping
- Implement register/unregister functions
- Add whereis for name lookup
- Add name_of for reverse lookup (Pid -> name)
- Prevent duplicate names and multiple names per process
- Add comprehensive tests with mutex for isolation

Enables Erlang-style named processes for easier discovery.
@unbalancedparentheses unbalancedparentheses changed the title feat: add process primitives (Pid, ProcessTable, Registry) [4/9] [4/9] feat: add process primitives (Pid, ProcessTable, Registry) Jan 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant