I have a stored procedure in mysql that performs a task that needs to be synchronized, so if two applications call the stored procedure, only one can access a section of code to complete the task, leaving the other lock until the first completes the task.
DELIMITER $$ CREATE PROCEDURE SP_GEN_ID(IN NAME VARCHAR(20)) BEGIN DECLARE maxLen int default 0; START TRANSACTION;
So, if two applications call the stored procedure at the same time, the task must be synchronized.
but. But Start TRANSACTION and COMMIT did NOT synchronize the execution.
b. And LOCK TABLES tableA cannot be used in a stored procedure to provide synchronization.
from. I tried to synchronize the stored procedure call at the application level. I used
boost_interprocess scoped_lock lock ();
It worked great in boost 1.41
But the interprocess lock mutex is not supported in boost 1.34 library, which is available in my case.
Is there a way to synchronize a section of a stored code procedure so that when two calls are made simultaneously, one of them will be blocked before the other is executed?
(added the following) edited code: to give an idea of ββwhat I'm trying to execute in a synchronized block of a stored procedure.
It receives the last assigned identifier and increments it by one and checks to see if it is being used for any other name entry. When the correct identifier is found, update the last assigned table of identifier entries, and then match this with the specified name.
DELIMITER $$ CREATE PROCEDURE SP_GEN_ID(IN NAME VARCHAR(20)) BEGIN DECLARE maxLen int default 0; START TRANSACTION;
synchronization mysql locking stored-procedures boost-interprocess
Flying dutchman
source share