fuzz: Remove unnecessary thread pool mutexes

Remove the `Mutex` from the `threadpool` and `dbwrapper_concurrent_reads`
pool startup helpers. Fuzz targets are entered sequentially within a
process and parallel fuzzing uses separate processes/forks, which each
have their own copy of the global thread pool. Therefore, a mutex to
prevent two in-process callers from racing to start the pool isn't needed.
This commit is contained in:
marcofleon
2026-06-17 13:53:50 +01:00
parent a4c3b003f8
commit 48df0939e7
2 changed files with 4 additions and 8 deletions

View File

@@ -174,11 +174,9 @@ constexpr size_t MAX_READ_WORKERS{8};
constexpr size_t MAX_READ_QUERIES_PER_WORKER{128};
ThreadPool g_read_pool{"dbfuzz"};
Mutex g_read_pool_mutex;
void StartReadPoolIfNeeded() EXCLUSIVE_LOCKS_REQUIRED(!g_read_pool_mutex)
void StartReadPoolIfNeeded()
{
LOCK(g_read_pool_mutex);
if (!g_read_pool.WorkersCount()) g_read_pool.Start(MAX_READ_WORKERS);
}
@@ -361,7 +359,7 @@ FUZZ_TARGET(dbwrapper_threaded, .init = [] { static auto setup{MakeNoLogFileCont
/*allow_force_compact=*/true);
}
FUZZ_TARGET(dbwrapper_concurrent_reads, .init = [] { static auto setup{MakeNoLogFileContext<>()}; }) EXCLUSIVE_LOCKS_REQUIRED(!g_read_pool_mutex)
FUZZ_TARGET(dbwrapper_concurrent_reads, .init = [] { static auto setup{MakeNoLogFileContext<>()}; })
{
StartReadPoolIfNeeded();
SeedRandomStateForTest(SeedRand::ZEROS);

View File

@@ -43,13 +43,11 @@ static void GetFuture(std::future<void>& future, uint32_t& fail_counter)
// instability in the fuzzing environment.
// This is also how we use it in the app's lifecycle.
ThreadPool g_pool{"fuzz"};
Mutex g_pool_mutex;
// Global to verify we always have the same number of threads.
size_t g_num_workers = 3;
static void StartPoolIfNeeded() EXCLUSIVE_LOCKS_REQUIRED(!g_pool_mutex)
static void StartPoolIfNeeded()
{
LOCK(g_pool_mutex);
if (g_pool.WorkersCount() == g_num_workers) return;
g_pool.Start(g_num_workers);
}
@@ -60,7 +58,7 @@ static void setup_threadpool_test()
LogInstance().DisableLogging();
}
FUZZ_TARGET(threadpool, .init = setup_threadpool_test) EXCLUSIVE_LOCKS_REQUIRED(!g_pool_mutex)
FUZZ_TARGET(threadpool, .init = setup_threadpool_test)
{
// Because LibAFL calls fork() after calling the init setup function,
// the child processes end up having one thread active and no workers.