Laurent Morichetti 6f78083f2a Fix a race condition when setting the callbacks
When acquiring the reader's lock (sem_sync()...sem_release()), it is
possible for a writer to squeeze by if the reader goes into sync_wait().
The writer could re-acquire the entry.sync between entry.sem > 0 and
entry.sync = 0.

void sync_wait(uint32_t id) {
    sem_decrement(id);
    while (entry(id).sync.load()) {}
    // <--- HERE
    sem_increment(id);
}

This could result in both the reader and the writer accessing
{ callback, arg } at the same time, and the reader could read
inconsistent data, for example: { new callback, old arg }.

The solution is to re-test entry.sync when returning from sync_wait():

void sem_sync(uint32_t id) {
    sem_increment(id);
-   if (entry(id).sync.load() == true) sync_wait(id);
+   while (entry(id).sync.load() == true) sync_wait(id);
}

Change-Id: I22f74f4cb9a5f027aac8aa4ed3e633acc19df4b8
2022-08-01 20:03:10 -04:00
S
Описание
No description provided
282 MiB
Languages
C++ 67.5%
C 20.6%
Python 6.6%
CMake 3.4%
Shell 0.6%
Разное 1.1%