19.08.2025 13:40, Adriano dos Santos Fernandes:
I don't see LM use such pattern. IIRC, the only "new" code, written before your ProfilerIpc,
that works asynchronously is MappingIpc.
> The problem happens only with the block marked as "// Problem - begin" /
> "// Problem - end", which is not necessary in the single-process test,
> but would be with multi-process.
>
> I verified that the problem happens in event_blocked function. Removing
> calls to event_blocked and letting WaitForSingleObject always be called,
> things works (very slow). And this looked very logical for me.
>
> I tried to make all event_t members atomic, but the problem still
> happens. I also tried to insert some memory fences, but no success.
>
> Can you help fix it?
There is two problems in this test:
1. consumer() initialized its eventCounter with zero, while eventClear(receiverEvent) must be
used instead. But consumer() runs asynchronously, thus it is not safe to call eventClear() at
that place. eventCounter = 1 fixes this problem, but it relays on the fact that there is just
one thread that waits on receiverEvent. Note, first call of eventClear() with just initialized
event returns 1, not 0.
2. More hard problem happens due to non-synchronized run of consumer against producer's.
It (consumer) sometimes read the stale data in senderEvent and eventPost(senderEvent) failed
with ERROR_INVALID_HANDLE. To demonstrate and workaround it, change
if (sharedMemory.eventPost(&header.senderEvent) != FB_SUCCESS)
(Arg::Gds(isc_random) << " eventPost failed").raise();
at line 194, by
static HANDLE h = header.senderEvent.event_handle;
while (sharedMemory.eventPost(&header.senderEvent) != FB_SUCCESS)
{
DWORD error = GetLastError();
string err;
err.printf("eventPost(senderEvent) failed: error=%d, event_handle=%d, h=%d. Continue...",
error, header.senderEvent.event_handle, h);
if (h != header.senderEvent.event_handle || error == ERROR_INVALID_HANDLE)
{
BOOST_TEST_MESSAGE(err.c_str());
continue;
}
BOOST_FAIL(err.c_str());
}
I've run the test with these changes 50 times successfully. 10 runs printed message like:
eventPost(senderEvent) failed: error=6, event_handle=864, h=676. Continue...
Regards,
Vlad