473,508 Members | 2,390 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Question about Synclock and multi threading

Suppose I have several threads that need to access the same object.
ThreadA successfully acquires the lock using SyncLock. ThreadB
attempts to acquire the lock and blocks and then ThreadC attempts to
acquire the lock and blocks.

When ThreadA releases the lock, will ThreadB get it before ThreadC by
virtue of the fact that ThreadB attempted to lock the object before
ThreadC did? Is there any way to enforce this sequence? I want to
make sure that ThreadB gets the lock BEFORE ThreadC. Is this possible?

Nov 21 '05 #1
7 1630
I don't think this is possible to enforce. The checking is done at a low
level according to the processor time-slicing.

The only way I can think of to do this is for thread B to release a mutex
that thread C is waiting on.
I might be wrong. This is a stab in the dark...

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Chris Dunaway" <du******@gmail.com> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
Suppose I have several threads that need to access the same object.
ThreadA successfully acquires the lock using SyncLock. ThreadB
attempts to acquire the lock and blocks and then ThreadC attempts to
acquire the lock and blocks.

When ThreadA releases the lock, will ThreadB get it before ThreadC by
virtue of the fact that ThreadB attempted to lock the object before
ThreadC did? Is there any way to enforce this sequence? I want to
make sure that ThreadB gets the lock BEFORE ThreadC. Is this possible?

Nov 21 '05 #2
Chris,

In my opinion are you typical talking about queued information.

I never used in VBNet however would have directly a look for that when I had
a problem as yours.

http://msdn.microsoft.com/library/de...ctmessaque.asp

Cor
Nov 21 '05 #3
Thanks for the replies. The queueing is not the problem. Consider the
following situation:

I have a queue in which orders are being queued and processed. There
are multiple threads retreiving items from the queue and processing
them. It is possible that two items on the queue might refer to the
same order, for example updates to the order. I need to make sure that
they occur in order. My first thought was to create a small object to
use to synchronize the threads. The first thread would acquire the
lock on that object. The second thread would wait for the lock to be
released, thereby keeping the correct sequence. But if there are 3
updates, and two are blocking, waiting for the first, I need to make
sure that the remaining two occur in order. The items will come off
the queue in order, but since there are multiple threads, I need to
make sure that they are processed in order.

Thanks again

Nov 21 '05 #4
Chris,

I write this very often, don't suspect to much from threads.
When I hear about your process than is bound to the processor.

Even when it is used on multiprocessorcomputers or with hyperthreading
processors.

Your process not the only process in your computer there are a lot others.

Consider if you real need multithreading.

My sample for very good use for multithreading is forever downloading from
sites with different speeds.

To say it in other words, processes than contains stops or when you have not
dependable different queues, than it can be a good solution, however when
the queus depends from each other, than it is in my opinion better to use
let it process by one thread. Otherwise the change that you create only
overhead with multiple threading is than very high.

However just my thought,

Cor
Nov 21 '05 #5
You have to rethink your design. In your design, as described below, you are
forcing an order to your threads and this will lead to thread serialization,
which takes away the purpose of using multiple threads in the first place.
"Chris Dunaway" <du******@gmail.com> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
Thanks for the replies. The queueing is not the problem. Consider the
following situation:

I have a queue in which orders are being queued and processed. There
are multiple threads retreiving items from the queue and processing
them. It is possible that two items on the queue might refer to the
same order, for example updates to the order. I need to make sure that
they occur in order. My first thought was to create a small object to
use to synchronize the threads. The first thread would acquire the
lock on that object. The second thread would wait for the lock to be
released, thereby keeping the correct sequence. But if there are 3
updates, and two are blocking, waiting for the first, I need to make
sure that the remaining two occur in order. The items will come off
the queue in order, but since there are multiple threads, I need to
make sure that they are processed in order.

Thanks again

Nov 21 '05 #6

Cor Ligthert wrote:
dependable different queues, than it can be a good solution, however when the queus depends from each other, than it is in my opinion better to use let it process by one thread. Otherwise the change that you create only overhead with multiple threading is than very high.


I only have one queue. The order data comes in the form of text files
(I cannot control this). Each text file multiple orders and has order
master records and order detail records. There are multiple orders
within a single file. The orders within the file are in order
sequentially. The files are created roughly every 15 minutes. There
exists the possibility that within a single file, there could be an
order and then later in the file an update to that order. I have to
make sure the order is processed before the update to the order. If I
used just a single thread, I wouldn't have to worry about this, but I
would like to use multiple threads because some orders may take longer
to process and I want to continue to process smaller orders, to keep
the up the throughput. I understand on a single processor, multiple
threads doesn't really speed things up, but I want to increase the
throughput of orders being processed.
Thanks again for the responses.

Nov 21 '05 #7
Chris,

I think that I (or any other) cannot help you, this is a lot of tuning
beside what is done in the multithreading

Your result will be a lot of overhead and as in the other message is showed,
are you in my opinion as well using a sequential process.

Thread a
Thread b wait on a
Thread a wait on b
Thread b wait on a

Cor
Nov 21 '05 #8

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

Similar topics

5
5432
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
3029
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...
10
3143
by: Bob Day | last post by:
Using vs 2003, vb.net sql msde.. Consider the following code snippets. See **** for questions. All are shared and accessed by multiple threads simultaneiously. ' Instantiate per for this...
6
3125
by: fniles | last post by:
I am using VB.NET 2003 and a socket control to receive and sending data to clients. As I receive data in 1 thread, I put it into an arraylist, and then I remove the data from arraylist and send it...
1
1560
by: Spam Catcher | last post by:
Hi all, I'm hosting a remoting service in IIS. I have a function which I only want one concurrent access at a time. Will this prevent multiple users from accessing the function at a paritcular...
10
4084
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
6
1023
by: fniles | last post by:
I am using VB.NET 2005 and thread. In each thread I open a database connection and before it exits the thread I close the database connection. Is there any way for me to count how many threads are...
3
395
by: Bill Schanks | last post by:
I have a form that gets opened, and it a separate thread I want a timer at the bottom of the form to update while the datagridview is updating. In my main form I have this: Dim t As New...
0
7323
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,...
1
7039
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
7494
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
5626
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5050
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...
0
4706
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3192
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1553
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
415
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.