List:MySQL++« Previous MessageNext Message »
From:anindh thomas Date:May 14 2010 8:09am
Subject:problem while handling concurrecy
View as plain text  
Sir,

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
connection pooling.

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.

Thankyou,

regards,
Anindh Thomas


Thread
problem while handling concurrecy anindh thomas14 May
  • Re: problem while handling concurrecyJonathan Wakely14 May
  • Re: problem while handling concurrecy Warren Young14 May