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. Synchronization

Synchronization

Scheduled Pinned Locked Moved C#
data-structureshelp
2 Posts 2 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
    rakesh_nits
    wrote on last edited by
    #1

    Hi All, I am having a function which can be called from different independent threads simultaneously.Inside this i am having a hashtable.what each thread will do that it will check whether the hashtable contains a particular key if not then it will make an entry in the hashtable with that key or if it exists it will simply use the value corresponding to that particular key.what i want that the access to the function should be on first come first serve basis.so if a thread is already waiting on the function the current thread after completing processing should leave it (should enter in succession only if there is not any waiting thread), and no thread should be kept waiting for infinite.so entry into the function should be related to time of waiting in short i want the impementation to be a queue like.is using lock(object) will be suffice for the task or i have to use something else. and also if you can tell me how this lock statement functions.whether it will cause the other statement to wait or simply not allow the other threads to access it and throw some error.Thanks in Advance. Rakesh

    C 1 Reply Last reply
    0
    • R rakesh_nits

      Hi All, I am having a function which can be called from different independent threads simultaneously.Inside this i am having a hashtable.what each thread will do that it will check whether the hashtable contains a particular key if not then it will make an entry in the hashtable with that key or if it exists it will simply use the value corresponding to that particular key.what i want that the access to the function should be on first come first serve basis.so if a thread is already waiting on the function the current thread after completing processing should leave it (should enter in succession only if there is not any waiting thread), and no thread should be kept waiting for infinite.so entry into the function should be related to time of waiting in short i want the impementation to be a queue like.is using lock(object) will be suffice for the task or i have to use something else. and also if you can tell me how this lock statement functions.whether it will cause the other statement to wait or simply not allow the other threads to access it and throw some error.Thanks in Advance. Rakesh

      C Offline
      C Offline
      Curtis Schlak
      wrote on last edited by
      #2

      From the documentation.

      [lock] marks a statement block as a critical section by obtaining the mutual-exclusion lock for a given object, executing a statement, and then releasing the lock

      However, you do not have the guarantee that it acts like a queue, only mutual exclusion on a thread-level basis. If you have an infinite condition in your lock block, then all other threads will wait forever. "we must lose precision to make significant statements about complex systems." -deKorvin on uncertainty

      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