Skip to content

Move work queue synchronization into the BLS ThreadPool #526

Description

@GrapeBaBa

Motivation

ThreadPool.JobQueue currently mixes queue storage and synchronization:

  • pushBatch acquires the queue mutex internally.
  • pop assumes the caller already holds the mutex.
  • workerLoop and deinit access the queue’s mutex and condition directly.
  • pushBatch receives the ThreadPool to inspect its shutdown state.

There is no known data race because current pop calls hold the mutex, but the locking contract is split
across JobQueue and ThreadPool. The queue is also not independently thread-safe as its comment suggests.

Proposed change

  • Keep the work queue as a plain, non-thread-safe data structure.
  • Move the mutex, condition variable, sleeping-worker count, and shutdown coordination to ThreadPool.
  • Make ThreadPool responsible for locking around all queue operations.
  • Guard the queue state and shutdown predicate with the same mutex.

The queue representation can remain unchanged or be replaced separately. The main goal is to make
synchronization ownership explicit and centralized in ThreadPool such as std.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: QuestionAdded to issues that are general discussion questions, and don't offer bug reports etc..

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions