Maratyszcza / pthreadpool

Portable (POSIX/Windows/Emscripten) thread pool for C/C++
BSD 2-Clause "Simplified" License
350 stars 133 forks source link

[Holding] Support Chromium's Jobs API integration #26

Closed huningxin closed 1 year ago

huningxin commented 1 year ago

The pthreadpool library is used by Chromium 1 for XNNPACK library which in turn supports TFLite and WebNN. Chromium has a Jobs API that is able to schedule a single worker task and request that ThreadPool workers invoke it in parallel 2.

This PR introduces changes wrapped by the PTHREADPOOL_USE_JOBS macro that support the integration with Chromium's Jobs API. In particular, this PR uses Chromium's base::Lock based execution_lock for pthreadpool struct. This lock will be used by Chromium's implementation of pthreadpool_parallelize() to serialize concurrent calls from different threads. Chromium's implementation of pthreadpool_parallelize() 3 is submitted to Chromium's repo and uses Jobs API to schedule parallel tasks with Chromium's ThreadPool workers.

To allow running pthreadpool unit tests with Chromium's Jobs API integration, this PR also introduces PthreadPoolTestBase as the base class of all test cases which sets up the test environment for Chromium's ThreadPool testing.

@Maratyszcza , PTAL, thanks!

huningxin commented 1 year ago

Please hold the review of this PR. There is on-going discussion at Chromium side that may not need this PR. I'll update once the design is finalized. Thanks!

huningxin commented 1 year ago

With Chromium CL-4608520 merged, there are no required changes of pthreadpool. I am closing this issue. Thanks!