Re: ManualResetEvent not thread safe??
jim.wiese_at_gmail.com
Date: 03/12/05
- Next message: Jac: "ASP.NET and Excel._Work***.SaveAs"
- Previous message: anon_at_anon.com: "Re: Need Help with a repeater and web custom control"
- Messages sorted by: [ date ] [ thread ]
Date: 12 Mar 2005 14:08:02 -0800
FYI: In case any runs into this article down the road. The
documentation for 1.1 SP1 now states:
Thread Safety
This type is safe for multithreaded operations.
Nicholas Paldino [.NET/C# MVP] wrote:
> John,
>
> The statement:
>
> Any public static (Shared in Visual Basic) members of this type are
safe for
> multithreaded operations. Any instance members are not guaranteed to
be
> thread safe.
>
> Is a general statement placed in the documentation for ALL
classes in
> the framework. However, mutexes and events are actually handled by
the
> underlying OS, and I believe that those synchronization primitives
are
> guaranteed by the OS to be thread-safe.
>
> Hope this helps.
>
>
> --
> - Nicholas Paldino [.NET/C# MVP]
> - casperOne@caspershouse.com
>
>
> "John" <yting2@san.rr.com> wrote in message
> news:ctju0v0qmbie8ppsvnl4r88vpg5rr3oeki@4ax.com...
> > Hi,
> >
> > I was trying to figure out whether two (or more) threads can Set()
the
> > same ManualResetEvent object _concurrently_ without being
> > synchronized:
> >
> > public class SomeClass
> > {
> > private Thread m_Thread1, m_Thread2, m_Thread3;
> > private ManualResetEvent m_Event;
> >
> > public void ThreadProc1() {
> > // This methods will be called by m_Thread1.
> > m_Event.Set();
> > }
> >
> > public void ThreadProc2() {
> > // This methods will be called by m_Thread2.
> > m_Event.Set();
> > }
> >
> > public void ThreadProc3() {
> > // This methods will be called by m_Thread3.
> > m_Event.WaitOne();
> > }
> > }
> >
> > In the above example, ThreadProc1 & ThreadProc2 may be called at
the
> > same time. They are not synchronized via Monitor, for example.
> >
> > While reading the VS .NET documentation for ManualResetEvent, I
> > noticed the following:
> >
> > "Any public static (Shared in Visual Basic) members of this type
are
> > safe for multithreaded operations. Any instance members are not
> > guaranteed to be thread safe."
> >
> > If the above statement is true, it means that:
> >
> > 1) ThreadProc1 & ThreadProc2 cannot be called from two different
> > threads at the same time because Set() is an instance member and
there
> > is no additional synchronization mechanism being applied (e.g.,
> > Monitor).
> >
> > 2) Similarly, ManualResetEvent.Set() & ManualResetEvent.WaitOne()
> > cannot be called from two differnet threads at the same time
because
> > both methods are non-static -- This does not make sense at all!!
> >
> > The same thing holds for Mutex.WaitOne() & Mutex.ReleaseMutex().
> > According to the documentation, it seems that two threads cannot
wait
> > for the same mutex concurrently because neither WaitOne() nor
> > ReleaseMutex() is static.
> >
> > I know there must be something wrong somewhere (possibly in the
> > documention). But can someone point out what's wrong with above
> > reasoning?
> >
> > Thanks in advance.
> >
> > --John
> >
- Next message: Jac: "ASP.NET and Excel._Work***.SaveAs"
- Previous message: anon_at_anon.com: "Re: Need Help with a repeater and web custom control"
- Messages sorted by: [ date ] [ thread ]