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. Algorithms
  4. Locking pattern to protect a critical List<> with many worker threads

Locking pattern to protect a critical List<> with many worker threads

Scheduled Pinned Locked Moved Algorithms
regexperformancequestion
24 Posts 5 Posters 332 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.
  • L Lost User

    Fine. You're not wrong, but you didn't have to be an ass about it. But that's nothing new for you.

    J Offline
    J Offline
    jschell
    wrote on last edited by
    #21

    Not sure how I am being an ass. You brought up shallow copy which was not in any way relevant. I can only respond to what you posted. Best I could guess was that you were using a different definition of shallow copy than I was. So I defined the term.

    1 Reply Last reply
    0
    • Richard Andrew x64R Richard Andrew x64

      My program contains a List<T> object that is extremely critical to the program's function. In normal use, it will be accessed by many ( >10 ) worker threads. I don't need to synchronize worker thread access, because the workers never write to the collection, it's read-only to the worker threads. However, I want to be able to make changes to the list in a single, central class. And I'd like to be able to temporarily shut off worker-thread access to the list while changes are being made by a thread in the central class. I'd like not to require the worker threads to acquire a mutex every time they need access due to performance reasons. So, is there a pattern by which I can make access to the List<T> very fast for the worker threads, but still be able to shut off worker access while the list is being updated by the central class?

      The difficult we do right away... ...the impossible takes slightly longer.

      C Offline
      C Offline
      charles henington
      wrote on last edited by
      #22

      In addition to what others have mentioned, could you not provide an EventHandler to notify of List Changing?

      Richard Andrew x64R 1 Reply Last reply
      0
      • C charles henington

        In addition to what others have mentioned, could you not provide an EventHandler to notify of List Changing?

        Richard Andrew x64R Offline
        Richard Andrew x64R Offline
        Richard Andrew x64
        wrote on last edited by
        #23

        You didn't complete the thought. What benefit would come from what you recommend?

        The difficult we do right away... ...the impossible takes slightly longer.

        C 1 Reply Last reply
        0
        • Richard Andrew x64R Richard Andrew x64

          You didn't complete the thought. What benefit would come from what you recommend?

          The difficult we do right away... ...the impossible takes slightly longer.

          C Offline
          C Offline
          charles henington
          wrote on last edited by
          #24

          You can use an EventHandler in conjunction with a EventWaitHandle to inform the worker thread that the list has changed and pass the new list so that the worker thread is always working with the new list rather than an old list.

          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