Skip to content

Implement pthread-based actor runtime with mailbox queuing#41

Open
ib823 wants to merge 1 commit intomainfrom
claude/actor-runtime-c-backend-TSBLz
Open

Implement pthread-based actor runtime with mailbox queuing#41
ib823 wants to merge 1 commit intomainfrom
claude/actor-runtime-c-backend-TSBLz

Conversation

@ib823
Copy link
Owner

@ib823 ib823 commented Mar 18, 2026

Summary

Implement a complete actor runtime system using POSIX threads (pthread), replacing stub implementations with functional mailbox-based message passing. Actors now have proper state management, thread synchronization primitives, and a ring-buffer mailbox for message queuing.

Changes

  • Add #include <pthread.h> to generated C code headers
  • Define riina_actor_type_t struct to store actor type metadata (init state and handler)
  • Define riina_actor_t struct with full runtime state: actor ID, state, handler, ring-buffer mailbox, pthread mutex, condition variable, and thread handle
  • Implement riina_actor_decl() to register actor types in a global type registry and return type ID
  • Implement riina_actor_spawn() to create actor instances with initialized pthread synchronization primitives
  • Implement riina_actor_send() with mutex-protected ring-buffer mailbox enqueuing and condition variable signaling
  • Implement riina_actor_recv() to return current actor state
  • Add comprehensive unit tests covering pthread includes, struct definitions, spawn initialization, mailbox operations, and type registry

Type

  • New feature

Testing

  • Added 5 new unit tests for actor runtime functionality:
    • test_emit_actor_pthread_include — verifies pthread header inclusion
    • test_emit_actor_struct_definition — verifies actor struct and synchronization primitives
    • test_emit_actor_spawn — verifies mutex/condition initialization on spawn
    • test_emit_actor_send_mailbox — verifies mailbox ring-buffer and locking
    • test_emit_actor_recv_returns_state — verifies state retrieval
    • test_emit_actor_decl_stores_type — verifies type registry storage

Checklist

  • No external dependencies added (pthread is POSIX standard)
  • No unsafe code in Rust (C code generation only)
  • New tests added for new functionality

https://claude.ai/code/session_01XLbQ6A6N4cKbjXDJ1iaDTU

Replace no-op actor stubs in the C backend with real implementations:
- Add pthread.h include for mutex/condvar support
- Add riina_actor_type_t registry for actor declarations
- Add riina_actor_t struct with ring buffer mailbox (256 slots),
  pthread_mutex_t, pthread_cond_t, and thread handle
- riina_actor_decl: stores handler + init_state in type registry
- riina_actor_spawn: initializes actor struct, mutex, condvar
- riina_actor_send: mutex-protected ring buffer enqueue with condvar signal
- riina_actor_recv: returns current actor state
- Add 6 new tests verifying pthread includes, struct definitions,
  spawn/send/recv code generation

https://claude.ai/code/session_01XLbQ6A6N4cKbjXDJ1iaDTU
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.

2 participants