473,657 Members | 2,428 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

CSingleLock Waiting Threads Execute in Order?

11 New Member
Hello everyone,

I have an application where multiple threads get passed to a processing method from a port. This method creates a CSingleLock on a CMutex object to ensure that only one thread executes at a time. Is there a way to ensure that the threads execute in the same order that they call the method?

IE - if there are 5 threads waiting on the same CMutex is there a way to ensure that the next thread that obtains the CMutex will be the first one that started waiting?
Apr 7 '11 #1
2 2786
hype261
207 New Member
I don't believe this is possible because the Operating System decides when threads get processor time.

Why can't you just use a basic queue in this case? If only one thread can execute in the processing method at a time then having a mutex and locking threading seems to be wasteful. Maybe there is a lot of processing going on before the thread gets passed to the processing method,
Apr 8 '11 #2
Ian Simpson
11 New Member
So I suppose you mean doing something like this.
Expand|Select|Wrap|Line Numbers
  1. Service_Processor::process_response(Message_Object* msg)
  2. {
  3.    thread_queue.push(GetCurrentThread());
  4.    if (thread_queue.size() > 0)
  5.    {
  6.       SuspendThread();
  7.    }
  8.    //Execute some callbacks or processing
  9.    thread_queue.pop();
  10.    if (thread_queue.size() > 0)
  11.    {
  12.       thread_queue.pop().Resume();
  13.    }
  14. }
  15.  
this is just the first idea that came to mind. I have no idea if it would work or not.
Apr 8 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
295
by: Russell Stuart | last post by:
I always believed .Net monitors were a superset of the Java synchronization mechanisms. The code below produces both "Thread 1" and "Thread 2" lines, implying that two threads are both executing in locked region guarded by the same monitor. I thought that wasn't supposed to happen. Am I wrong? It was compiled and run under VS 2003. If you run it under the debugger then the behaviour changes - only "Thread 1" lines are produced. ...
5
3845
by: bughunter | last post by:
Hi, Consider this code: ---- Monitor.Pulse(oLock); Monitor.Exit(oLock); ---- If a thread was waiting on oLock then will the current thread
13
2509
by: orekin | last post by:
Hi There I have been programming C# for a couple of months and am trying to master Threading. I understand that ThreadPool uses background threads (see code example in MSDN page titled 'ThreadPool Class ') .... however I would like to ensure that all my ThreadPool threads have completed before I exit my Main function.
10
1675
by: [Yosi] | last post by:
I would like to know how threads behavior in .NET . When an application create 4 threads for example start all of them, the OS task manager will execute all 4 thread in deterministic order manes, OS execute (All have same priority) Thread#1 may be other threads, Thread#2 may be other threads, Thread#3 may be other threads,
3
12591
by: Elhurzen | last post by:
X-No-Archive: Yes >From what I understand, if multiple threads are waiting on a ManualResetEvent after calling WaitOne(), only one thread is guaranteed to be signaled when Set() is called on that ManualResetEvent. How do I ensure that _all_ waiting threads are signaled, without sacrificing any of the functionality or much of the simplicity of ManualResetEvent? Example: SignalingClass:
2
1446
by: darrel | last post by:
I've been struggling with a page that is set up like this: PAGE: ------------------ control 1 - reads a cookie and executes stuff based on that control 2 - reads the same cookie and can also set the value ------------------ So, the logical layout for control 2 was this:
12
2002
by: emma_middlebrook | last post by:
Hi Say you had N threads doing some jobs (not from a shared queue or anything like that, they each know how to do their own set of jobs in a self-contained way). How can you coordinate them so that they all wait until they've all done one job before starting off on each of their next jobs. I have been thinking about this for a day and can't seem to find a solution.
0
1205
by: =?Utf-8?B?QmVu?= | last post by:
Hello, I need to use the functionality of an AutoResetEvent in that it should normally be non-signalled, but I want something to be able to release all the waiting threads when I call Set, however AutoResetEvent.Set only releases one thread. ManualResetEvent isn't really appropriate because it should remain non-signalled, i.e. when any thread calls WaitOne() it always needs to block until 'nudged'. Is ManualResetEvent.Set() immediately...
5
3650
by: nimitsis | last post by:
Hello to everyone I wont to create 2 threads in Python ( thread01, thread02 ), which doing the follows : thread01, ask user to give a value to flag variable and write it to the shared memory of two threads thread02, read from shared memory and check if the flag have a specific value . The corresponding python code follows: import time import thread import threading import Numeric, sys
2
1168
by: Gabriel Genellina | last post by:
En Tue, 13 May 2008 06:42:13 -0300, Astan Chee <stanc@al.com.auescribió: I'm confused trying to understand your requirements too. "run a class?" Threads execute code, it's easier to think of them as *functions* that are executed at the same time (or almost). So you have a function A that runs first, and creates a second thread that will execute function B. Then A will wait for B to finish. What do you want to do in A while it's...
0
8420
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
8516
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8617
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6176
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5642
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2743
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 we have to send another system
2
1970
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1733
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.