473,417 Members | 1,530 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,417 software developers and data experts.

Use SyncLock or Monitor on a binary tree

Ken
I have a binary tree in VB NET and insertions seem to be slow.

The program receives data from one source and inserts it into the tree.

The program receives data from another source and looks the data up in the
tree.

When inserting data into the tree, access seems to be denied the other
thread while the insert(s) are taking place. (250 - 3000 records to insert
at time)

I currently have no synchronization in place.

Should I use "SyncLock" or "Monitor" to control the access of each of the
threads?

I have not had this problem with VB6 or VC++6. I thought VB NET would at
least be an improvement over VB6, but that does not seem to be true in this
case - unless, of course, I do require some synchronization method to
achieve the same throughput.

Any ideas or thoughts would be welcome.
Nov 21 '05 #1
4 2932
Ken,

As long as there is in one thread only written while that data is not to be
used in the other thread, than there has nothign to be synchronized. However
as soon as that data had indexes or whatever than it has.

Be aware that if it does not crash, than that is probably not the problem.

A multithreading program will need forever more processing time. Only if
there are parallel processes can the total throughput time be increased by
multithreading.

I hope this gives a simple idea, you given information is in my opinion to
less to give us more idea's

I hope that it helps anyway.

Cor
Nov 21 '05 #2
Ken,

Adding synchronization to an already slow operation is just going to
make it slower. Though, if your data structure really does need to be
accessed by more than one thread then you have no choice. You must use
SyncLock, Monitor, or other synchronization techniques.

How do you know that access is being denied to the data structure from
thread A when thread B is writing? If you're not using any
synchronization then neither thread A or B will block. How do you know
that multiple threads are even involved?

What kind of binary tree are you using?

Brian

Ken wrote:
I have a binary tree in VB NET and insertions seem to be slow.

The program receives data from one source and inserts it into the tree.

The program receives data from another source and looks the data up in the
tree.

When inserting data into the tree, access seems to be denied the other
thread while the insert(s) are taking place. (250 - 3000 records to insert
at time)

I currently have no synchronization in place.

Should I use "SyncLock" or "Monitor" to control the access of each of the
threads?

I have not had this problem with VB6 or VC++6. I thought VB NET would at
least be an improvement over VB6, but that does not seem to be true in this
case - unless, of course, I do require some synchronization method to
achieve the same throughput.

Any ideas or thoughts would be welcome.


Nov 21 '05 #3
Ken
Brian, thanks for the interest.

"How do you know that access is being denied to the data structure from
thread A when thread B is writing?'

If I perform lookups while no data is being loaded into the tree, then the
response time is acceptable. However, if data is being loaded into the tree
while I am attempting lookups, the response time can (doesn't always) span
long periods of time (7 seconds - 1 minute).

"If you're not using any synchronization then neither thread A or B will
block. How do you know
that multiple threads are even involved?"

I am assuming that multiple threads are involved because of the noticeable
problem I stated above.
If I am only performing the lookup, then the response is good.
If I am only loading data, then the response is good.
"What kind of binary tree are you using?"

A hashed index of 1000 binary trees. Not balanced.

If we used a Social Security number to insert into the tree. (<-- Not what I
am using, just call it an ID - all numbers)

Dim SSN as String
SSN = "123-45-6789"
HashTree(789).Insert(SSN)

In the tree, I look at the root node. If it is empty, this SSN would go
there. If not empty, check to see if SSN is Less or Greater than Root. Less
goes left, greater goes right.

You can see how this could become more like a linked list. I'm sure portions
of it do resemble a linked list.

I don't think that is the problem. I can put 100,000 items in a collection,
array, or linked list and access the last element much faster than 7 or 8
seconds.

One last thing: Data is received and loaded via TCPIP. Data is retrieved via
serial communications.

*******
The processor spikes as the data is being loaded into the tree from the
sockets. This is when the most notable delays in the serial communications
occur.

Are the serial ports being denied access while the large amount of data is
being loaded, or is the processor too busy to entertain any more requests
until the load finishes?
*******

VS2005, I understand, is supposed to have serial and socket support. I have
VS .Net 2003.
"Brian Gideon" <br*********@yahoo.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Ken,

Adding synchronization to an already slow operation is just going to
make it slower. Though, if your data structure really does need to be
accessed by more than one thread then you have no choice. You must use
SyncLock, Monitor, or other synchronization techniques.

How do you know that access is being denied to the data structure from
thread A when thread B is writing? If you're not using any
synchronization then neither thread A or B will block. How do you know
that multiple threads are even involved?

What kind of binary tree are you using?

Brian

Ken wrote:
I have a binary tree in VB NET and insertions seem to be slow.

The program receives data from one source and inserts it into the tree.

The program receives data from another source and looks the data up in the tree.

When inserting data into the tree, access seems to be denied the other
thread while the insert(s) are taking place. (250 - 3000 records to insert at time)

I currently have no synchronization in place.

Should I use "SyncLock" or "Monitor" to control the access of each of the threads?

I have not had this problem with VB6 or VC++6. I thought VB NET would at
least be an improvement over VB6, but that does not seem to be true in this case - unless, of course, I do require some synchronization method to
achieve the same throughput.

Any ideas or thoughts would be welcome.

Nov 21 '05 #4
Ken,

I don't think I can explain the performance issue without seeing some
code or having more information. But, based on what you've said about
sockets and serial communication I'm more comfortable with your
assertion that more than one thread is involved. If that's the case
then you will need to synchronization access to the data structure.

Have you tried profiling the application to see what's taking so long
reading the data structure?

Brian

Ken wrote:
Brian, thanks for the interest.

"How do you know that access is being denied to the data structure from
thread A when thread B is writing?'

If I perform lookups while no data is being loaded into the tree, then the
response time is acceptable. However, if data is being loaded into the tree
while I am attempting lookups, the response time can (doesn't always) span
long periods of time (7 seconds - 1 minute).

"If you're not using any synchronization then neither thread A or B will
block. How do you know
that multiple threads are even involved?"

I am assuming that multiple threads are involved because of the noticeable
problem I stated above.
If I am only performing the lookup, then the response is good.
If I am only loading data, then the response is good.
"What kind of binary tree are you using?"

A hashed index of 1000 binary trees. Not balanced.

If we used a Social Security number to insert into the tree. (<-- Not what I
am using, just call it an ID - all numbers)

Dim SSN as String
SSN = "123-45-6789"
HashTree(789).Insert(SSN)

In the tree, I look at the root node. If it is empty, this SSN would go
there. If not empty, check to see if SSN is Less or Greater than Root. Less
goes left, greater goes right.

You can see how this could become more like a linked list. I'm sure portions
of it do resemble a linked list.

I don't think that is the problem. I can put 100,000 items in a collection,
array, or linked list and access the last element much faster than 7 or 8
seconds.

One last thing: Data is received and loaded via TCPIP. Data is retrieved via
serial communications.

*******
The processor spikes as the data is being loaded into the tree from the
sockets. This is when the most notable delays in the serial communications
occur.

Are the serial ports being denied access while the large amount of data is
being loaded, or is the processor too busy to entertain any more requests
until the load finishes?
*******

VS2005, I understand, is supposed to have serial and socket support. I have
VS .Net 2003.


Nov 21 '05 #5

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

Similar topics

5
by: MS Newsgroups | last post by:
Hi, If i have a remoting component hosted on a server that exposes a method that does some file IO operations, and i want to avoid this method to be run at the same time from client applications...
12
by: Keith Langer | last post by:
I have some questions about whether synclock is necessary in a few different scenarios: 1) I have a Queue class which is shared between two threads. Thread 1 pushes objects onto the queue and...
2
by: Eric Newton | last post by:
I find it curious that the Synclock...End Synclock do not emit a try finally as well... SyncLock Me Me.someOperation() End SyncLock I would expect to see in the generated code: try...
3
by: Bob Day | last post by:
Ok, I have done a lot of reading(of the newsgroup answers, help files and MSDN articles) of synclock. I understand what you are saying in the newsgroup, and it is very helpful. It does, however,...
3
by: Chris Dunaway | last post by:
I was using a Queue object like this to create my own specialized queue class for use with my own objects: Public Class MySpecializedQueue Private q As New Queue Public Sub Enqueue(obj As...
1
by: Perecli Manole | last post by:
Can an Exit Sub statement in a SyncLock block cause any problems with the proper release of the locked resource or affect the Monitor's waiting queue in any way? Thanks Perry
2
by: HONOREDANCESTOR | last post by:
I have a buffer that needs to be locked sometimes, because 2 processes update it. So I made the buffer into a class and whenever there is code that affects it, I sandwich the code between ...
10
by: Frank Osterberg | last post by:
Hi, I want to simultaneously SyncLock multiple objects, something like: SyncLock objA, objB ' do stuff with objA and objB
2
by: cj | last post by:
I take it a mutex is like a synclock but visible outside the program?
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.