Skip to content

refactor: SG-44489: Replace several boost threading usages with std::thread and address sanitizer reported issues - #1313

Open
markreidvfx wants to merge 9 commits into
AcademySoftwareFoundation:mainfrom
markreidvfx:nas_contrib_boost_thread_to_std_v1
Open

refactor: SG-44489: Replace several boost threading usages with std::thread and address sanitizer reported issues#1313
markreidvfx wants to merge 9 commits into
AcademySoftwareFoundation:mainfrom
markreidvfx:nas_contrib_boost_thread_to_std_v1

Conversation

@markreidvfx

Copy link
Copy Markdown
Contributor

Summarize your change.

Replace Boost threading primitives (boost::mutex, boost::thread_group, raw pthreads) with C++ standard library equivalents (std::mutex, std::thread, std::lock_guard, std::condition_variable). Also fix two issues identified by sanitizers: remove unused threadState code (AddressSanitizer new-delete-type-mismatch) and defer thread start in TwkMediaLibrary until after construction (ThreadSanitizer data race).

Describe the reason for the change.

The Boost threading wrappers add unnecessary complexity and dependencies. The stl_ext::thread_group implementation used raw pthreads with manual mutex/cond management and a complex worker dispatch model. Replacing it with std::thread, std::queue, and std::condition_variable simplifies the code significantly (net reduction of ~600 lines) and removes platform-specific timing code. The two bug fixes address real issues found by AddressSanitizer and ThreadSanitizer.

Describe what you have tested and on which operating system.

Tested on Rocky Linux 9.

Add a list of changes, and note any that might need special attention during the review.

  • Thread.h / Thread.cpp: Remove unused threadState code flagged by AddressSanitizer.
  • Library.h / Library.cpp: Defer thread start until after construction; remove threadTrampoline wrapper.
  • ALSAAudioRenderer.h/.cpp, ALSASafeAudioRenderer.h/.cpp: Replace boost::mutex with std::mutex.
  • ThreadedMovie.h/.cpp: Replace boost::mutex with std::mutex and adopt std::lock_guard. Fixes m_runLock not being destroyed previously.
  • MovieFBWriter.cpp: Replace boost::mutex with std::mutex.
  • thread_group.h / thread_group.cpp: Rewrite to use std::thread, std::queue, std::mutex, std::condition_variable. Remove raw pthreads, cancel(), and platform-specific timing. Net reduction of ~600 lines.
  • Various main.cpp files: Remove unused boost::thread_group includes.

AddressSanitizer identified a new-delete-type-mismatch in
threadState. The feature is unused anywhere in the codebase;
removing it eliminates the bug and the dead code.

Signed-off-by: Mark Reid <markreid@netflixanimation.com>
Starting a thread in the constructor risks accessing members still
being initialized. Identified by ThreadSanitizer. Add an explicit
start() method called post-construction and remove the unnecessary
threadTrampoline wrapper.

Signed-off-by: Mark Reid <markreid@netflixanimation.com>
Signed-off-by: Mark Reid <markreid@netflixanimation.com>
Signed-off-by: Mark Reid <markreid@netflixanimation.com>
Signed-off-by: Mark Reid <markreid@netflixanimation.com>
m_runLock was not being destroyed previously.

Signed-off-by: Mark Reid <markreid@netflixanimation.com>
Signed-off-by: Mark Reid <markreid@netflixanimation.com>
Signed-off-by: Mark Reid <markreid@netflixanimation.com>
Rewrite stl_ext::thread_group to use C++ standard library threading
primitives instead of raw pthreads wrappers.

- Replace manual pthread_mutex/cond lock/unlock/signal/broadcast
  helpers with std::mutex, std::condition_variable, and std::lock_guard
- Replace the complex worker-wait/signal dispatch model with a
  std::queue<Job> work queue that workers pull from
- Simplify thread_main from a three-phase wait/jump/cleanup cycle
  to a straightforward dequeue-and-execute loop
- Merge dispatch() and maybe_dispatch() into a single
  internal_dispatch() that pushes to the queue
- Simplify destructor: set m_running=false, notify all, join. No
  more noop dispatch workaround or manual mutex/cond teardown
- Replace platform-specific gettimeofday/GetSystemTimeAsFileTime
  with std::chrono
- Remove cancel() (pthread_cancel) which was unsafe
- Net reduction of ~600 lines

Signed-off-by: Mark Reid <markreid@netflixanimation.com>
@markreidvfx markreidvfx changed the title Replace several Boost threading usages with std::thread and address sanitizer reported issues refactor: Replace several boost threading usages with std::thread and address sanitizer reported issues Jun 22, 2026
@bernie-laberge bernie-laberge changed the title refactor: Replace several boost threading usages with std::thread and address sanitizer reported issues refactor: SG-44489: Replace several boost threading usages with std::thread and address sanitizer reported issues Jul 23, 2026
@bernie-laberge bernie-laberge added PR: Acknowledged New PR has been acknowledge by the TSC community Contribution from the Open RV Community PR: Planned_P1 PR will be review and set soon. Expect 1 to 4 weeks delay. and removed PR: Acknowledged New PR has been acknowledge by the TSC labels Jul 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community Contribution from the Open RV Community PR: Planned_P1 PR will be review and set soon. Expect 1 to 4 weeks delay.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants