Re: Threading newbie: Lock statement

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Jan wrote:
Does the "lock" statement lock the "ressource" or the code section (like a critical section)?

Let me elaborate: I have two threads accessing the same ressource, but from *different* parts of the code. Can I use the lock statement to synchronise access, or can I only use lock when the threads access the ressource from the *same* part of he code (critical section). MSDN is somewhat unclear about this.

You can lock on the same object from different code
and achieve the desired synchronization.

But remember - it is still 100% cooperative locking.

Arne
.



Relevant Pages

  • Re: Threading newbie: Lock statement
    ... Let me elaborate: I have two threads accessing the same ressource, ... Can I use the lock statement to ... synchronise access, or can I only use lock when the threads access the ... ressource from the *same* part of he code. ...
    (microsoft.public.dotnet.languages.csharp)
  • Threading newbie: Lock statement
    ... I have two threads accessing the same ressource, ... Can I use the lock statement to synchronise ... public static void MySecondThreadProcedure() ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: problem with pthread_mutex_timedlock
    ... and if the lock was not free, it returns the error code 110, but I have ... function expects an *absolute time* for the timeout, ... // try to lock the ressource again. ...
    (comp.os.linux.development.apps)