Skip to content

Commit

Permalink
Fixing global semaphore deadlock for NIX platforms
Browse files Browse the repository at this point in the history
If the program crashed or behaved unexpectedly while a global semaphore was locked, that semaphore would stay locked until the machine was restarted. Unlinking the semaphore upon creation will cause the semaphore to be disposed of once the last process using that semaphore is no longer running.
  • Loading branch information
colincornaby committed Jul 13, 2024
1 parent f405924 commit e58372d
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Sources/Plasma/CoreLib/hsThread_Unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ hsGlobalSemaphore::hsGlobalSemaphore(int initialValue, const ST::string& name)

/* Named semaphore shared between processes */
fPSema = sem_open(semName.c_str(), O_CREAT, 0666, initialValue);
// Unlink it immediately so it will be freed if we unexpectedly leave it locked
sem_unlink(semName.c_str());
if (fPSema == SEM_FAILED)
{
hsAssert(0, "hsOSException");
Expand Down

0 comments on commit e58372d

Please sign in to comment.