Skip to content

Implement thread-safe libc with proper locking #339

@pbalduino

Description

@pbalduino

Goal

Add thread-safety to global libc state with proper locking to enable safe concurrent use of C standard library.

Context

Currently, libc has no concurrency protection:

  • stdio buffers (FILE* streams) aren't locked
  • Environment variable access isn't protected
  • Allocator (malloc/free) may not be thread-safe
  • Global state (errno, strtok static buffer, etc.) has no protection

With pthread support (#109), programs will crash or corrupt data when multiple threads use libc simultaneously.

Definition of Done

  • Thread-safe stdio (flockfile/funlockfile, per-FILE mutexes)
  • Thread-safe environment (getenv/putenv/setenv locking)
  • Thread-safe allocator (malloc/free locking if needed)
  • Thread-local errno
  • Reentrant variants (_r functions: strtok_r, localtime_r, etc.)
  • Testing with multithreaded programs

Dependencies

Required

Related

Priority

Medium - Required after pthread implementation

Estimated Time

6-8 weeks part-time

Metadata

Metadata

Assignees

Labels

libcC standard library implementation

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions