MySQL Locks: order of unblocked threads
I have a MySQL ISAM table being accessed my multiple php instances. Right now I'm using a WR开发者_如何学CITE
lock to serialize access to this table.
My question is how do I ensure that the PHP instances get served on a First-Come-First-Serve basis? Or is this the default behaviour?
The official MySQL documentation doesn't mention anything about the blocked thread order for threads of the same lock type (ie multiple threads attempting a WRITE LOCK). It only mentions that a WRITER will jump to the front of the waiting queue if READERS are waiting.
If the docs call it a "queue", that tends to mean "first come, first served".
All lock requests are put in a lock queue. That way your write locks will be handled in the same order as they were received by the mysql server.
This is default behaviour.
You only have to make sure your requests are made in the wanted order.
精彩评论