Named mutex synchronization primitive example
#include <iostream>
#include <string>
int main(int argc, char** argv)
{
std::string help = "Please enter '+' to lock and '-' to unlock the named mutex (several processes support). Enter '0' to exit...";
std::cout << help << std::endl;
std::string line;
while (getline(std::cin, line))
{
if (line == "+")
{
std::cout << "Mutex successfully locked!" << std::endl;
else
std::cout << "Failed to lock mutex!" << std::endl;
}
else if (line == "-")
{
try
{
std::cout << "Mutex successfully unlocked!" << std::endl;
}
{
std::cout << "Failed to unlock mutex!" << std::endl;
}
}
else if (line == "0")
break;
else
std::cout << help << std::endl;
}
return 0;
}
Named mutex synchronization primitive.
bool TryLock()
Try to acquire mutex without block.
void Unlock()
Release mutex.
Named mutex synchronization primitive definition.