Problem with Threads
-
Hi All, Again problem with Threads.In an application I am creating three threads each thread trying to call a interface function(This function tries to add records to a Database) of a Component.CCI is succeeding ,I am getting Interface pointer.Since each Thread tries to add the Record there should be 3 Records in Database.But, there are only 2 records.I am using CreateThread(...) for creating the Threads.In the Debug mode there is no such problem.There are 3 Records added to the Database.Also, if in this scenario I give Sleep(0) then no problem . Where am I going wrong ? Thanx in advance for the help. Regards, yamini
-
Hi All, Again problem with Threads.In an application I am creating three threads each thread trying to call a interface function(This function tries to add records to a Database) of a Component.CCI is succeeding ,I am getting Interface pointer.Since each Thread tries to add the Record there should be 3 Records in Database.But, there are only 2 records.I am using CreateThread(...) for creating the Threads.In the Debug mode there is no such problem.There are 3 Records added to the Database.Also, if in this scenario I give Sleep(0) then no problem . Where am I going wrong ? Thanx in advance for the help. Regards, yamini
-
What kind of database is it, if it's sql server, maybe try to put a store procedure and then the interface should call it. :eek:
Hi, I am using MS Access Database(no stored queries).I am sure the problem is not with Interface pointer as while Debugging the program works perfectly.So,pls tell me if there is problem with some other part if the application I have mentioned .
-
Hi All, Again problem with Threads.In an application I am creating three threads each thread trying to call a interface function(This function tries to add records to a Database) of a Component.CCI is succeeding ,I am getting Interface pointer.Since each Thread tries to add the Record there should be 3 Records in Database.But, there are only 2 records.I am using CreateThread(...) for creating the Threads.In the Debug mode there is no such problem.There are 3 Records added to the Database.Also, if in this scenario I give Sleep(0) then no problem . Where am I going wrong ? Thanx in advance for the help. Regards, yamini
Need to know a bit more. Is the component shared among threads? What threading model is being used? Is a shared DB connection being used? One thing that springs to mind about debug ~vs~ release is the speed. As release is faster, it may be causing a problem. How does Access do its locking, is it per row, table or block? if per table or block you may need to synchronise access to the DB to prevent collisions. HTH.
-
Hi All, Again problem with Threads.In an application I am creating three threads each thread trying to call a interface function(This function tries to add records to a Database) of a Component.CCI is succeeding ,I am getting Interface pointer.Since each Thread tries to add the Record there should be 3 Records in Database.But, there are only 2 records.I am using CreateThread(...) for creating the Threads.In the Debug mode there is no such problem.There are 3 Records added to the Database.Also, if in this scenario I give Sleep(0) then no problem . Where am I going wrong ? Thanx in advance for the help. Regards, yamini
Without knowing all of the facts here is my guess: This sounds like a classic "race" condition. The database record lock and your writes in the threads collide with each other. To prove if this is the case try adding three different, long delays to the threads (e.g. Sleep( 100 ), Sleep( 200 ), Sleep( 300 ). If this works, your database and interface is OK and you have a timing problem. You must synchronise the writes or retry on error. Have Fun!!!