473,386 Members | 1,786 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Collection and synchronisation.

Hi List,

I have a question on collection synchronisation. For example I have an
ArrayList called myList and the code is like this:

lock (myList.SyncRoot)
{
// do update on myList
Monitor.PulseAll(myList.SyncRoot);
}

Question, do I need to do Monitor.PulseAll() in here? Because the code above
is potentially accessed by several thread.

Thanks,

Wes
Jul 21 '05 #1
3 1539
Not sure what your doing, but you don't need pulse here. All other threads
will block on lock (if they lock the same syncRoot instance) and be release
in turn as lock is released. hth

--
William Stacey, MVP

"wesley" <we*@inthemix.com.au> wrote in message
news:uh**************@TK2MSFTNGP10.phx.gbl...
Hi List,

I have a question on collection synchronisation. For example I have an
ArrayList called myList and the code is like this:

lock (myList.SyncRoot)
{
// do update on myList
Monitor.PulseAll(myList.SyncRoot);
}

Question, do I need to do Monitor.PulseAll() in here? Because the code above is potentially accessed by several thread.

Thanks,

Wes


Jul 21 '05 #2
Thanks,

I got confused a bit with the Monitor.Pulse/PulseAll doc because it says
here:
"The thread that currently owns the lock on the specified object invokes
this method to signal all threads waiting to acquire the lock on the object.
After the signal is sent, the waiting threads are moved to the ready queue.
When the thread that invoked PulseAll releases the lock, the next thread in
the ready queue acquires the lock."

So I thought I need to do Pulse so the other thread waiting can try to get
the lock.

Thanks,

wes
Not sure what your doing, but you don't need pulse here. All other threads will block on lock (if they lock the same syncRoot instance) and be release in turn as lock is released. hth

--
William Stacey, MVP
Hi List,

I have a question on collection synchronisation. For example I have an
ArrayList called myList and the code is like this:

lock (myList.SyncRoot)
{
// do update on myList
Monitor.PulseAll(myList.SyncRoot);
}

Question, do I need to do Monitor.PulseAll() in here? Because the code

above
is potentially accessed by several thread.

Thanks,

Wes

Jul 21 '05 #3
That is when your doing fancier stuff with monitor and waits, etc (i.e.
readers and writers). Normally you can just use "lock()" for many things.
lock actualy is sugar for Monitor.

--
William Stacey, MVP

"wesley" <we*@inthemix.com.au> wrote in message
news:Of**************@TK2MSFTNGP11.phx.gbl...
Thanks,

I got confused a bit with the Monitor.Pulse/PulseAll doc because it says
here:
"The thread that currently owns the lock on the specified object invokes
this method to signal all threads waiting to acquire the lock on the object. After the signal is sent, the waiting threads are moved to the ready queue. When the thread that invoked PulseAll releases the lock, the next thread in the ready queue acquires the lock."

So I thought I need to do Pulse so the other thread waiting can try to get
the lock.

Thanks,

wes
Not sure what your doing, but you don't need pulse here. All other

threads
will block on lock (if they lock the same syncRoot instance) and be

release
in turn as lock is released. hth

--
William Stacey, MVP
Hi List,

I have a question on collection synchronisation. For example I have an
ArrayList called myList and the code is like this:

lock (myList.SyncRoot)
{
// do update on myList
Monitor.PulseAll(myList.SyncRoot);
}

Question, do I need to do Monitor.PulseAll() in here? Because the code

above
is potentially accessed by several thread.

Thanks,

Wes



Jul 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Dumbo Liz | last post by:
Hi I hold a Design Master for development and synchronise this weekly with my colleague who enters data and runs reports. This has worked well for the last 3 months. (He e-mails me a copy and I'm...
0
by: Tony Epton | last post by:
I am not quite a newbie in the area of SQL server - more "knows just enough to be dangerous" - so please be gentle with me. Cross posted to several groups - apologies if too far off topic I...
0
by: Ondine | last post by:
I have a client running Access 2000 on a desktop (win 98) acting as the 'server' and a Sony Viaio notebook (win 2000). They are synchronising and the data on the laptop is continually getting...
3
by: wesley | last post by:
Hi List, I have a question on collection synchronisation. For example I have an ArrayList called myList and the code is like this: lock (myList.SyncRoot) { // do update on myList...
9
by: Dave G | last post by:
The unexpected problem is this - say, 2 pcs called A and B, both running my Access program, both arranged in a FE/BE arrangement. There is an unbound form in the program. When the form opens all...
0
by: tbb | last post by:
Hi is it possible to do the synchronisation of the briefcase programmatically? Greets tim
1
by: chengsi | last post by:
Hello, I am trying to create a button which users can click to activate the synchronisation process within a replica set without having to use the MS Access menus or the Database window (as both...
19
by: Hapa | last post by:
Does only reading (never writing) of a variable need thread synchronisation? Thanks for help? PS. Anybody knows a Visual C++ news group?
4
by: sujatha k | last post by:
I want to create one window service to synchronice my local database with server database.i've done the synchronization process in .net application it is working fine. i copied tat code and put it in...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.