On 8/26/25 22:58, Adriano dos Santos Fernandes wrote:
>
> (I may even have found something weird (not sure) already, were a
> multi-thread test works in debug mode but does not in release).
>
And here is a snippet of kind of test I want to write which such refactor:
----
std::vector<std::thread> threads;
std::latch latch(THREAD_COUNT);
std::mutex mutex;
for (unsigned threadNum = 0u; threadNum < THREAD_COUNT; ++threadNum)
{
threads.emplace_back([&]() {
const UCHAR LOCK_KEY[] = {'1'};
FbLocalStatus statusVector;
LOCK_OWNER_T ownerId = threadNum + 1;
SLONG ownerHandle = 0;
lockManager->initializeOwner(&statusVector, ownerId,
LCK_OWNER_attachment, &ownerHandle);
latch.arrive_and_wait();
for (unsigned i = 0; i < ITERATION_COUNT; ++i)
{
// std::lock_guard mutexGuard(mutex);
const auto lockId = lockManager->enqueue(callbacks, &statusVector, 0,
LCK_expression, LOCK_KEY, sizeof(LOCK_KEY), LCK_EX, nullptr,
nullptr, 0, LCK_WAIT, ownerHandle);
if (lockId)
{
++lockSuccess;
lockManager->dequeue(lockId);
}
else
++lockFail;
}
lockManager->shutdownOwner(callbacks, &ownerHandle);
});
}
for (auto& thread : threads)
thread.join();
----
With the mutexGuard commented, it consistently hangs or calls
LockManager::bug.
Adriano