MySQL MariaDB – What is a Semaphore Wait?

mariadbMySQL

I got the following error in my MariaDB 10.x hostname.err log:

InnoDB: ###### Diagnostic info printed to the standard error stream
InnoDB: Error: semaphore wait has lasted > 600 seconds
InnoDB: We intentionally crash the server, because it appears to be hung.

Can someone please explain (as simply as possible ;-D) what a "semaphore wait" is within the context of MySQL/MariaDB?

All I could gather from Mr. Google is that they are "related to internal synchronization between threads in mysqld"

Best Answer

Semaphores throttle access to a resource. If it's not available a process has to wait until it is. Very long waits can signal that you have a deadlock situation and something needs to be killed to break it up.

https://stackoverflow.com/questions/2332765/lock-mutex-semaphore-whats-the-difference

A lock allows only one thread to enter the part that's locked and the lock is not shared with any other processes.

A mutex is the same as a lock but it can be system wide (shared by multiple processes).

A semaphore does the same as a mutex but allows x number of threads to enter, this can be used for example to limit the number of cpu, io or ram intensive tasks running at the same time.