I have a multithreaded C++ application which uses mysql.Here i am using mysqlpp
library for handling the mysql connectivity.I am also using thread-safe
Now coming to the issue,I have a table with two fields id and status(0 or 1).i
want to take the smallest id with status 0 and then update the status field to 1
in the corresponding record.
The problem is as i have multiple threads doing these operations.two or more
threads may get the same id and update the table causing an overwrite.To handle
this i applied a mutex lock before the select statement that retrieves the id
and later release the lock after updating the status field in the table.
Using the locks did solve the concurrency issue but if the number of such
operations increase, the delay is also increasing,which compromises my purpose.
I tried to find the cause of the delay and it seems that the select statement is
taking too much time (in range of 10-20 milliseconds).
Could you please suggest me possible ways to handle both,the concurrency issue
as well as the delay.