Skip to content

C SDK: Document thread safety requirements and fix js_cleanup #23

@clemensv

Description

@clemensv

Problem

The C SDK has thread safety concerns that need to be addressed:

Issues Found

  1. Global allocator is unprotected - \g_allocator\ in \ ypes.c\ is mutable global state with no synchronization
  2. \js_init()/\js_cleanup()\ are not thread-safe - Modifying global allocator during active validations causes undefined behavior
  3. \js_cleanup()\ doesn't clear regex cache - Should call \js_regex_cache_clear()\

Current Behavior

  • Validators are safe for concurrent use IF \js_init()\ is called once before any threads start
  • \js_set_allocator()\ must NEVER be called while validators are active
  • Each thread must use its own \js_result_t\ for results

Required Changes

  1. Add thread safety documentation to README
  2. Fix \js_cleanup()\ to clear the regex cache
  3. Consider making \g_allocator\ immutable after initialization (optional)

Tests to Add

  • Test concurrent validation from multiple threads (pthreads)
  • Test that regex cache is cleared on \js_cleanup()\
  • Test calling \js_init()\ multiple times is idempotent

Thread Safety Classification

Partially Thread-Safe - Safe with proper usage patterns documented

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions