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#
  4. Thread Safe Generic Dictionary Collection

Thread Safe Generic Dictionary Collection

Scheduled Pinned Locked Moved C#
comperformancehelpquestion
7 Posts 5 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.
  • W Offline
    W Offline
    Waleed Eissa
    wrote on last edited by
    #1

    Hi, has anybody written or come across a thread-safe generic dictionary collection? I need it for a project of mine, I want a fully thread-safe dictionary (ie. with no lock wrapping add and remove only) but with high performance as it will be used in a web application. Thanks for any help.

    Waleed Eissa Software Developer Sydney

    L E D B 4 Replies Last reply
    0
    • W Waleed Eissa

      Hi, has anybody written or come across a thread-safe generic dictionary collection? I need it for a project of mine, I want a fully thread-safe dictionary (ie. with no lock wrapping add and remove only) but with high performance as it will be used in a web application. Thanks for any help.

      Waleed Eissa Software Developer Sydney

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      Why not just override where you need to?

      xacc.ide - now with TabsToSpaces support
      IronScheme - 1.0 alpha 4a out now (29 May 2008)

      1 Reply Last reply
      0
      • W Waleed Eissa

        Hi, has anybody written or come across a thread-safe generic dictionary collection? I need it for a project of mine, I want a fully thread-safe dictionary (ie. with no lock wrapping add and remove only) but with high performance as it will be used in a web application. Thanks for any help.

        Waleed Eissa Software Developer Sydney

        E Offline
        E Offline
        Ennis Ray Lynch Jr
        wrote on last edited by
        #3

        Lock wrapping is required for thread-safety. Without the locking you get dirty reads which can cause a lot of problems in the system. Of course with only add and remove methods I am left wondering how you would use the dictionary.

        Need a C# Consultant? I'm available.
        Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway

        W 1 Reply Last reply
        0
        • W Waleed Eissa

          Hi, has anybody written or come across a thread-safe generic dictionary collection? I need it for a project of mine, I want a fully thread-safe dictionary (ie. with no lock wrapping add and remove only) but with high performance as it will be used in a web application. Thanks for any help.

          Waleed Eissa Software Developer Sydney

          D Offline
          D Offline
          Daniel Grunwald
          wrote on last edited by
          #4

          If there are lots of concurrent reads and only occasional writes, you could try to use the ReaderWriterLockSlim[^]. If that's still too much locking for your app, you're looking for a lock-free hash table[^]. (according to the presentation, this starts to be faster than locking at >32 processors)

          W 1 Reply Last reply
          0
          • E Ennis Ray Lynch Jr

            Lock wrapping is required for thread-safety. Without the locking you get dirty reads which can cause a lot of problems in the system. Of course with only add and remove methods I am left wondering how you would use the dictionary.

            Need a C# Consultant? I'm available.
            Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway

            W Offline
            W Offline
            Waleed Eissa
            wrote on last edited by
            #5

            I'm sorry, I don't quite understand your reply. Locking is fine in Add() and Remove() but locking the dictionary every time you try to look up a value is certainly an overkill, this is what I meant when I referred to performance.

            Ennis Ray Lynch, Jr. wrote:

            Of course with only add and remove methods I am left wondering how you would use the dictionary.

            I meant using lock in only Add() and Remove(), I didn't mean a dictionary which only exposes Add() and Remove() :)

            Waleed Eissa Software Developer Sydney

            1 Reply Last reply
            0
            • D Daniel Grunwald

              If there are lots of concurrent reads and only occasional writes, you could try to use the ReaderWriterLockSlim[^]. If that's still too much locking for your app, you're looking for a lock-free hash table[^]. (according to the presentation, this starts to be faster than locking at >32 processors)

              W Offline
              W Offline
              Waleed Eissa
              wrote on last edited by
              #6

              This is just what I'm looking for, I think I'm going for the ReaderWriterLockSlim as the dictionary will be used mostly for reading with occasional writes. Thanks a million!

              Waleed Eissa Software Developer Sydney

              1 Reply Last reply
              0
              • W Waleed Eissa

                Hi, has anybody written or come across a thread-safe generic dictionary collection? I need it for a project of mine, I want a fully thread-safe dictionary (ie. with no lock wrapping add and remove only) but with high performance as it will be used in a web application. Thanks for any help.

                Waleed Eissa Software Developer Sydney

                B Offline
                B Offline
                BrianMarkR
                wrote on last edited by
                #7

                http://devplanet.com/blogs/brianr/archive/2008/09/26/thread-safe-dictionary-in-net.aspx[^]

                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