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. Question On Multithreading Lock

Question On Multithreading Lock

Scheduled Pinned Locked Moved C#
questioncsharp
3 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.
  • C Offline
    C Offline
    cateyes99
    wrote on last edited by
    #1

    Within the multithreading enviroments, there is an exclusive lock provided by the .Net, which will block all other threads trying to enter the critical section if currently there is a threading holding this critical section. But I'm trying to find a unblocking lock whick is exclusive but won't block other threads, just let them return and inform them the critical section is not available for them to access. Anyone knows if there is this kind of lock? Thanks a lot;)

    D 1 Reply Last reply
    0
    • C cateyes99

      Within the multithreading enviroments, there is an exclusive lock provided by the .Net, which will block all other threads trying to enter the critical section if currently there is a threading holding this critical section. But I'm trying to find a unblocking lock whick is exclusive but won't block other threads, just let them return and inform them the critical section is not available for them to access. Anyone knows if there is this kind of lock? Thanks a lot;)

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

      lock (obj) {
      //...
      }

      is just a syntax sugar for:

      System.Threading.Monitor.Enter(obj);
      try {
      //...
      } finally {
      System.Threading.Monitor.Exit(obj);
      }

      You should take a look at the other Monitor methods, there's a method called "TryEnter".

      C 1 Reply Last reply
      0
      • D Daniel Grunwald

        lock (obj) {
        //...
        }

        is just a syntax sugar for:

        System.Threading.Monitor.Enter(obj);
        try {
        //...
        } finally {
        System.Threading.Monitor.Exit(obj);
        }

        You should take a look at the other Monitor methods, there's a method called "TryEnter".

        C Offline
        C Offline
        cateyes99
        wrote on last edited by
        #3

        Thanks very much, it's really helpful!:laugh:

        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