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. Only one thread accessing the CList object

Only one thread accessing the CList object

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
6 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.
  • R Offline
    R Offline
    Rsh
    wrote on last edited by
    #1

    I want a sample program to create two threads & only one thread access the CList object at a time. that is, one thread uses some(i don't know which) synchronization object to lock the CList object & writes to it and then releases the CList object. Next another thread does the same process, but instead of writing, it reads from the CList. can anybody help? Rsh

    A A J 3 Replies Last reply
    0
    • R Rsh

      I want a sample program to create two threads & only one thread access the CList object at a time. that is, one thread uses some(i don't know which) synchronization object to lock the CList object & writes to it and then releases the CList object. Next another thread does the same process, but instead of writing, it reads from the CList. can anybody help? Rsh

      A Offline
      A Offline
      Andres Manggini
      wrote on last edited by
      #2

      I'm sorry but time is not my friend right now to make an example, but you can start searching for this on MSDN: CMutex or CCriticalSection. Hope this helps. PS: if you have installed the MSDN Help from Visual Studio.NET then use this address: ms-help://MS.VSCC/MS.MSDNVS/vccore/html/_core_Multithreading.3a_.How_to_Use_the_Synchronization_Classes.htm Andres Manggini. Buenos Aires - Argentina.

      1 Reply Last reply
      0
      • R Rsh

        I want a sample program to create two threads & only one thread access the CList object at a time. that is, one thread uses some(i don't know which) synchronization object to lock the CList object & writes to it and then releases the CList object. Next another thread does the same process, but instead of writing, it reads from the CList. can anybody help? Rsh

        A Offline
        A Offline
        Alexandru Savescu
        wrote on last edited by
        #3

        You should use something like this:

        CCriticalSection cs; // this object must be global of static in your class

        // then in the function that access the CList
        void CMyClass::FunctionThatAccessTheCList ()
        {
        // lock this section, begins the synchronized section
        cs.Lock ();
        //.... modify the list here

        cs.Unlock ();
        // end synchronized section
        }

        Best regards, Alexandru Savescu

        R 1 Reply Last reply
        0
        • R Rsh

          I want a sample program to create two threads & only one thread access the CList object at a time. that is, one thread uses some(i don't know which) synchronization object to lock the CList object & writes to it and then releases the CList object. Next another thread does the same process, but instead of writing, it reads from the CList. can anybody help? Rsh

          J Offline
          J Offline
          Joaquin M Lopez Munoz
          wrote on last edited by
          #4

          This post of mine explains a convenient approach to synchronizing access to a data structure. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

          R 1 Reply Last reply
          0
          • J Joaquin M Lopez Munoz

            This post of mine explains a convenient approach to synchronizing access to a data structure. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

            R Offline
            R Offline
            Rsh
            wrote on last edited by
            #5

            Thank u Joaquín This made my life more easier :) Rsh

            1 Reply Last reply
            0
            • A Alexandru Savescu

              You should use something like this:

              CCriticalSection cs; // this object must be global of static in your class

              // then in the function that access the CList
              void CMyClass::FunctionThatAccessTheCList ()
              {
              // lock this section, begins the synchronized section
              cs.Lock ();
              //.... modify the list here

              cs.Unlock ();
              // end synchronized section
              }

              Best regards, Alexandru Savescu

              R Offline
              R Offline
              Rsh
              wrote on last edited by
              #6

              Pretyy cool one Thanx Alexandru Rsh

              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