Handling Concurrency
Posted by: Anindh Thomas
Date: May 13, 2010 07:38AM

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

Options: ReplyQuote


Subject
Views
Written By
Posted
Handling Concurrency
729
May 13, 2010 07:38AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.