[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1898
  • Last Modified:

MySQL; "Atomic" operation test & set for exclusivity

In some processor's microarchitecture, there's an atomic operation for test and set, such that a bit can be tested (the results stored) and the bit set, all guaranteed without interruption,  for the purpose of process synchronization.

How can i have a MySQL bit to indicate that a record is locked for editing, and thus at the beginning of the code that does the editing, i do a test and set, and deny entry into the critical code region if the bit was found to have been already set, else set it and proceed into the critical code section.

i can approximate this with two adjacent statements,
SELECT bit FROM....
UPDATE ... SET bit=1

but surely there is a built-in way to guarantee no intervening interruption btwn the two queries.

thanks
0
willsherwood
Asked:
willsherwood
1 Solution
 
rokovCommented:
Put your statements within a transaction (begin..commit block) for this.
More details about transactions in MySQL: http://www.databasejournal.com/features/mysql/article.php/3382171
0
 
willsherwoodAuthor Commented:
perfect, thanks!
0

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now