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. about two or more processes ReadWrite a file simultaneity?

about two or more processes ReadWrite a file simultaneity?

Scheduled Pinned Locked Moved C / C++ / MFC
jsonquestion
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.
  • H Offline
    H Offline
    HOW WHAT
    wrote on last edited by
    #1

    like this: 1.When No.1 process reading a.txt, No.2 process read a.txt simultaneity, both read as usual. 2.When No.1 process reading a.txt, No.2 process write a.txt, No.2 process wait No.1 process read complete then write. 3.When No.1 process writting a.txt, No.2 process read a.txt, No.2 process wait No.1 process write complete then read. 4.When No.1 process writting a.txt, No.2 process write a.txt, No.2 process wait No.1 process write complete then write. How use _locking(CRT functions) or LockFile, UnlockFile(Window API) finish above. it puzzled me someday. If somebody know, please tell me.Thanks very much.

    C N 2 Replies Last reply
    0
    • H HOW WHAT

      like this: 1.When No.1 process reading a.txt, No.2 process read a.txt simultaneity, both read as usual. 2.When No.1 process reading a.txt, No.2 process write a.txt, No.2 process wait No.1 process read complete then write. 3.When No.1 process writting a.txt, No.2 process read a.txt, No.2 process wait No.1 process write complete then read. 4.When No.1 process writting a.txt, No.2 process write a.txt, No.2 process wait No.1 process write complete then write. How use _locking(CRT functions) or LockFile, UnlockFile(Window API) finish above. it puzzled me someday. If somebody know, please tell me.Thanks very much.

      C Offline
      C Offline
      chandu004
      wrote on last edited by
      #2

      use some global flags(may be two or three), which indicate the state of the other thread. say for example, int process1flag=0,process2flag=0; and make the flag 1 if it is writing and make it 2 if it is reading. after write or read operations, reset them to 0. observe the same in the other process and take the decission depending on the flags.

      Suggestion to the members: prefix your main thread subject with [SOLVED] if it is solved. chandu.

      N 1 Reply Last reply
      0
      • H HOW WHAT

        like this: 1.When No.1 process reading a.txt, No.2 process read a.txt simultaneity, both read as usual. 2.When No.1 process reading a.txt, No.2 process write a.txt, No.2 process wait No.1 process read complete then write. 3.When No.1 process writting a.txt, No.2 process read a.txt, No.2 process wait No.1 process write complete then read. 4.When No.1 process writting a.txt, No.2 process write a.txt, No.2 process wait No.1 process write complete then write. How use _locking(CRT functions) or LockFile, UnlockFile(Window API) finish above. it puzzled me someday. If somebody know, please tell me.Thanks very much.

        N Offline
        N Offline
        Naveen
        wrote on last edited by
        #3

        You should use some synchronization with the help of Mutex. Check CreateMutex(), WaitForSingleObject() and ReleaseMutex(). You can find many samples in CP that uses mutex.

        nave [OpenedFileFinder]

        1 Reply Last reply
        0
        • C chandu004

          use some global flags(may be two or three), which indicate the state of the other thread. say for example, int process1flag=0,process2flag=0; and make the flag 1 if it is writing and make it 2 if it is reading. after write or read operations, reset them to 0. observe the same in the other process and take the decission depending on the flags.

          Suggestion to the members: prefix your main thread subject with [SOLVED] if it is solved. chandu.

          N Offline
          N Offline
          Naveen
          wrote on last edited by
          #4

          chandu004 wrote:

          which indicate the state of the other thread

          He is talking about different process not different thread.

          nave [OpenedFileFinder]

          C 1 Reply Last reply
          0
          • N Naveen

            chandu004 wrote:

            which indicate the state of the other thread

            He is talking about different process not different thread.

            nave [OpenedFileFinder]

            C Offline
            C Offline
            chandu004
            wrote on last edited by
            #5

            ok.

            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