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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. how to use multiThread to read and write database?

how to use multiThread to read and write database?

Scheduled Pinned Locked Moved C / C++ / MFC
databasetutorialquestion
5 Posts 3 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.
  • C Offline
    C Offline
    caiguosen
    wrote on last edited by
    #1

    I want to use multiThread to read and write database,but I do not how how to prevent the thread from reading db again and again, for example, I want use Thread1 to read record 1 - 100,and use Thread2 to read record 101-200,but I don`t know how to control different threads to read different data?

    CPalliniC D 2 Replies Last reply
    0
    • C caiguosen

      I want to use multiThread to read and write database,but I do not how how to prevent the thread from reading db again and again, for example, I want use Thread1 to read record 1 - 100,and use Thread2 to read record 101-200,but I don`t know how to control different threads to read different data?

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      Thread synchronization is a big topic. Have a look at MSDN [^]. :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
      [My articles]

      In testa che avete, signor di Ceprano?

      1 Reply Last reply
      0
      • C caiguosen

        I want to use multiThread to read and write database,but I do not how how to prevent the thread from reading db again and again, for example, I want use Thread1 to read record 1 - 100,and use Thread2 to read record 101-200,but I don`t know how to control different threads to read different data?

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        caiguosen wrote:

        ...but I don`t know how to control different threads to read different data?

        Is thread 2 not supposed to read until thread 1 finishes?

        "One man's wage rise is another man's price increase." - Harold Wilson

        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

        "Man who follows car will be exhausted." - Confucius

        C 1 Reply Last reply
        0
        • D David Crow

          caiguosen wrote:

          ...but I don`t know how to control different threads to read different data?

          Is thread 2 not supposed to read until thread 1 finishes?

          "One man's wage rise is another man's price increase." - Harold Wilson

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          "Man who follows car will be exhausted." - Confucius

          C Offline
          C Offline
          caiguosen
          wrote on last edited by
          #4

          they can read together,but the content which thread one reads can not be read by thread2. there will be many threads, just like client/server mode, but how can i control these threads in order to let them read different data from the same database.

          D 1 Reply Last reply
          0
          • C caiguosen

            they can read together,but the content which thread one reads can not be read by thread2. there will be many threads, just like client/server mode, but how can i control these threads in order to let them read different data from the same database.

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            I've never tried anything like this, but my first attempt would be to set some sort of filter (i.e., WHERE clause), like:

            SELECT * FROM table WHERE 1 <= rownum AND rownum <= 100 // thread 1
            SELECT * FROM table WHERE 101 <= rownum AND rownum <= 200 // thread 2
            SELECT * FROM table WHERE 201 <= rownum AND rownum <= 300 // thread 3

            Does that sound plausible?

            "One man's wage rise is another man's price increase." - Harold Wilson

            "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

            "Man who follows car will be exhausted." - Confucius

            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