Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Problem with Threads

Problem with Threads

Scheduled Pinned Locked Moved C / C++ / MFC
helpdatabasedebuggingquestion
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    yamini
    wrote on last edited by
    #1

    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

    H B J 3 Replies Last reply
    0
    • Y 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

      H Offline
      H Offline
      Hushpappy
      wrote on last edited by
      #2

      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:

      Y 1 Reply Last reply
      0
      • H Hushpappy

        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:

        Y Offline
        Y Offline
        yamini
        wrote on last edited by
        #3

        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 .

        1 Reply Last reply
        0
        • Y 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

          B Offline
          B Offline
          Bob Groves
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • Y 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

            J Offline
            J Offline
            Joe Moldovan
            wrote on last edited by
            #5

            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!!!

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups