Search notes:

System.Threading.Mutex

Powershell 7 example

In a Powershell 7 session, we create a mutex:
PS C:\> [bool] $newMutex = $false
PS C:\> $mutex = new-object System.Threading.Mutex($true, 'mtxTQ84', [ref] $newMutex)
PS C:\> $newMutex
True
In another Powershell 7 session, we create a mutex with the same name.
After creating the mutex, the value of $newMutex is False and indicates that the name was already known:
PS C:\> [bool] $newMutex = $false
PS C:\> $mutex = new-object System.Threading.Mutex($true, 'mtxTQ84', [ref] $newMutex)
PS C:\> $newMutex
False
In the second session, we wait until the first session releases the mutex:
PS C:\> $mutex.WaitOne()
We then release the mutex in the first session. Note how the blocked second session becomes unblocked:
PS C:\> $mutex.ReleaseMutex()
We now wait in the first session until the second session releases the mutex ‥
PS C:\> $mutex.WaitOne()
‥ and release the mutex in the first session:
PS C:\> $mutex.ReleaseMutex()

See also

Using mutexes with thread jobs to prevent race conditions.

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:51 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(51): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(66): id_of(Object(PDO), 'uri', '/notes/Microsof...') #2 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/Microsof...', 1758209358, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #3 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/Microsoft/dot-net/namespaces-classes/System/Threading/Mutex/index(69): insert_webrequest() #4 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 51