Skip to content

Commit

Permalink
SharedLibrary: ensure that there is no race condition when multiple t…
Browse files Browse the repository at this point in the history
…hreads call the close method
  • Loading branch information
traversaro committed Oct 26, 2024
1 parent 95a3098 commit b71da03
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/libYARP_os/src/yarp/os/SharedLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <yarp/os/Log.h>

#include <mutex>
#include <string>

#ifdef YARP_HAS_ACE
Expand Down Expand Up @@ -49,6 +50,9 @@ class yarp::os::impl::SharedLibraryImpl
#else
void* dll;
#endif
// Ensure that there are no race condition when two
// different threads both call the close method
std::mutex closeMutex;
std::string error;
};

Expand Down Expand Up @@ -100,6 +104,7 @@ bool SharedLibrary::open(const char* filename)

bool SharedLibrary::close()
{
std::lock_guard<std::mutex> lockGuard(implementation->closeMutex);
int result = 0;
if (implementation->dll != nullptr) {
#ifdef YARP_HAS_ACE
Expand Down

0 comments on commit b71da03

Please sign in to comment.