|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Re: framework 1.1 & Queue classOn Apr 24, 2:59 am, "oscar.acostamonte***@googlemail.com"
<oscar.acostamonte***@googlemail.com> wrote: > Hello: Just to clarify...the object used in the lock statement must be the> Also you can use a sync object, and place queue acces code in a lock > statement. > object o = new object(); > lock(o){ > //Queue operations...} > > Best regards. > Oscar Acosta same in every thread to guarentee thread-safety. It's difficult to ascertain what your intention from the code was precisely, but one way to read it is that the variable o is local and thus would be different on every thread. On Apr 24, 3:30 pm, Brian Gideon <briangid***@yahoo.com> wrote:
Show quote > On Apr 24, 2:59 am, "oscar.acostamonte***@googlemail.com" Yes, you're rigth, code is not clear. Object o should be a class> > <oscar.acostamonte***@googlemail.com> wrote: > > Hello: > > Also you can use a sync object, and place queue acces code in a lock > > statement. > > object o = new object(); > > lock(o){ > > //Queue operations...} > > > Best regards. > > Oscar Acosta > > Just to clarify...the object used in the lock statement must be the > same in every thread to guarentee thread-safety. It's difficult to > ascertain what your intention from the code was precisely, but one way > to read it is that the variable o is local and thus would be different > on every thread. memeber, with class scope, so it is always locking on same object. public class Queue{ private static readonly object o = new object(); private void ReadQueue(){ lock(o){ int nValue = (int)localQueue.Dequeue(); Console.WriteLine("Read from Queue: {0}", nValue); } } } Best regards Oscar Acosta |
|||||||||||||||||||||||