473,231 Members | 1,706 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,231 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 2918
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
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.