473,397 Members | 2,033 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,397 software developers and data experts.

CSingleLock Waiting Threads Execute in Order?

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

✓ answered by hype261

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,

2 2768
hype261
207 100+
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
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
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...
5
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
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...
10
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,...
3
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...
2
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...
12
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...
0
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...
5
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...
2
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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,...
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.