I want my function to only run once. Meaning that if many threads call it at the same time, the function will block all threads apart from one and only allow it to run.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It sounds like you want the stored procedure to do the synchronization. Why not just put the synchronization in the application itself.
If you need to provide synchronization at the database level, you can use the LOCK and UNLOCK TABLES commands within your stored procedure. Lock on entry to the procedure and unlock on exit. Depending on your needs, it may be that you’ll want to create a dummy table that is locked and unlocked instead of an actual data table in use by this and other processes. See here for more details.