Re: lock used in thread and by event



On Sep 25, 1:47 pm, uupi_...@xxxxxxxxx wrote:
There's no such thing as "first thread's method" though.

Yes there are. Don't make this too hard...

No, there really isn't. The sooner you express yourself clearly in
accepted terminology, the sooner we'll solve your problem.

We can also use Abstraction when posting to news.

If I say first thread's method that means there is a class that is a
thread,

But again, that breaks down. A class isn't a thread. Multiple threads
can run the same method in the same object at the same time.

In other words: it's not clear what you mean when you write "a class
that is a thread" or "a thread's method".

It *would* be clear if you'd produce a short but complete program,
however.

<snip>

So, some action now! "First method is executing method y and comes to
line where lock(x) is executed. At the same time "second thread" fires an
event which calls first thread's (synonym can be now class in this case ) eventhandler
(method z) which also executes it's lock(x) line.

If it's *genuinely* a second thread and the locks are *genuinely* to
the same reference,
then the second thread will block.

I know that if second thread (class) call directly without Event first
threads (class) method then
lock(x) will block in eventhandler z (we assume now that eventhandler
Z can be called directly like method).

Sorry, but you've lost me again. It would be *much* simpler to write
this in code rather than in text which uses terminology in a non-
standard way.

If you know what is Java's ReentrantLock you should understand this
question :)

I've already said that locks in C# (and .NET in general) are re-
entrant. Java's ReentrantLock has (as per the API documentation) "the
same basic behavior and semantics as the implicit monitor lock
accessed using synchronized methods" - and Java's synchronization is
very similar to .NET's.

In other words, within one thread you can indeed do:

lock (foo)
{
lock (foo) // No blocking here
{
...
}
}

But if you really, really have a second thread trying to acquire a
lock while another thread holds that lock, the second thread *will*
block until the holding thread releases the lock.

Jon

.



Relevant Pages

  • Re: Ensuring that a thread doesnt own a critical section within a function
    ... fix is to specify that 'f' cannot be called while holding the lock. ... purpose of the 'f' function is to wait for the second thread to change ... The purpose of the lock is to ... prevent the thing the second thread messes with from changing state. ...
    (comp.programming.threads)
  • Re: Interrupting threads...
    ... The solution highly depends of the whole environment you are working on ... why should the second thread fails to ... > Lets say i have 1 mutex, ... > if it's abandoned i'll get the lock in "thread2" anyways). ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Creating a Shared Lock
    ... A second thread that is called once every second ... needs to lock so the other function does not get called while its running. ... In SQL you would do this by creating a shared lock on the first function ... shared access but once a thread has an exclusive lock any shared locks will ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: monitor
    ... > This situation wont happen beacause the second thread already owns the ... The first thread have to wait until the second thread calls ... After the finally block the thread still owns the lock on *this*. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Dynamic reads without locking.
    ... JH>> Jeffrey Hsu was talking about this at BSDCon03. ... JH>> There is no need to lock data when we just made simple read, ... JH>> bar = foo; ... So the compiler is free to compile this as ...
    (freebsd-hackers)

Loading