473,698 Members | 2,246 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

threading waiting on message queues

Hello,

Here is my challenge.

I have a thread awaiting events being sent via Queue. Currently I am
checking the count and if there is a count, Dequeue() the next object
and process it. By design, however, this is inefficient usage of CPU
clocks.

A more efficient usage could be to wrap Monitor::Wait() and
Monitor::Pulse( ) events. If Monitor operations like I think it does, I
should be able to Wait() efficiently forever for the next event to
arrive and before I Dequeue() it. And use Pulse() to signal when a
next event has been Enqueue()d.

Does Wait() wait efficiently for the next pulse to arrive?
Are pulses queued cumulatively?
Or is there only one state (pulsed or not)?
(Not insurmountable if this cannot happen.)

Best regards,
Michael Powell
Nov 17 '05 #1
1 1304
Mike wrote:
Hello,

Here is my challenge.

I have a thread awaiting events being sent via Queue. Currently I am
checking the count and if there is a count, Dequeue() the next object
and process it. By design, however, this is inefficient usage of CPU
clocks.

A more efficient usage could be to wrap Monitor::Wait() and
Monitor::Pulse( ) events. If Monitor operations like I think it does, I
should be able to Wait() efficiently forever for the next event to
arrive and before I Dequeue() it. And use Pulse() to signal when a
next event has been Enqueue()d.

Does Wait() wait efficiently for the next pulse to arrive?
Yes.
Are pulses queued cumulatively?
No.
Or is there only one state (pulsed or not)?
Yes. The states are more like owned & unowned but the implication is (I
think) what you're looking for: Monitor::Pulse will wake a single waiting
thread a single time.
(Not insurmountable if this cannot happen.)


The docs in MSDN on Montor::Wait, Pulse, PulseAll are pretty thorough - be
sure to start by reading and understanding all of those.

-cd
Nov 17 '05 #2

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

Similar topics

1
2142
by: Lane LiaBraaten | last post by:
I am developing a GUI that uses multiple threading.Threads, and Queue.Queues for communicating between the threads, and threading.Timers for checking the queues. Everything works well (runs to completion and exits) on my RedHat7.3 machine, but it doesn't work (hangs like some thread or queue is blocking)on RH9. However, when I ssh into the RH9 box from my RH7.3 box, the app runs fine(on my RH7.3 screen). Now the madness sets...
4
1263
by: Alban Hertroys | last post by:
Hello all, I need your wisdom again. I'm working on a multi-threaded application that handles multiple data sources in small batches each time. The idea is that there are 3 threads that run simultaneously, each read a fixed number of records, and then they wait for eachother. After that the main thread does some processing, and the threads are allowed to continue reading data. I summarized this part of the application in the attached...
15
1638
by: chahnaz.ourzikene | last post by:
Hi all, This is the first i post in this newsgroup, i hope my english is not too bad... Let's get straight to the point ! I have a little probleme using threads in my little training example : I wish to create two threads in my application, one thread (the subject) will increment a variable, and another thread (the controller) will print a message saying "i am waiting..." or someting like that, until the counter of the first thread...
1
1476
by: Ognjen Bezanov | last post by:
Hi, all Thanks all of you who helped me with the threading and queues issue. I am trying to get it working but I am having problems. When I try to run the following: cmddata = mediaplay.initcommandqueue() #initiates the Queue to send commands down
2
19002
by: Gulshan Oshan | last post by:
I want to implement a simple console that continuously listens for an event from a custom object. I am unable to capture the events from the object. If I subscribe to the events in a windows app it works fine. Any idea? using System; using MyTestApp.Messaging; using MyTestApp.BusinessLayer; using System.Threading;
0
1180
by: Stephen Barrett | last post by:
After reading through the many many many posts on threading, I still don't quite understand how to accomplish a task. Here is an overview of the app I am coding. I am sorry if it is a little long. A Windows Service app (no probs here) that basically needs to look for work to do from 1 to many MSMQ queues that it then needs to pass on to 1 to many (configurable) worker threads to process. The worker thread actually runs a few...
3
2382
by: Elliot Rodriguez | last post by:
Hi: I am writing a WinForm app that contains a DataGrid control and a StatusBar control. My goal is to update the status bar using events from a separate class, as well as some other simple things. The method I am writing queries a large dataset. As part of my feedback to the user, I am updating the status bar when the connection is made and the dataset is actually retrieved. The dataset retrieval method I have placed on a separate...
13
1806
by: John | last post by:
I've got some reasonably complex business logic in my C# code, in a class called by a ASP.NET page. This takes around 3-4 seconds to execute. It's not dependent on SQL calls or anything like that. I know of the problems with the worker process doing two things at once from the main thread pool (The old "Sit in a tight loop for 20 seconds and watch all your webapps die!" issue). So I've worked around the issue by spawning the business...
19
1797
by: frankiespark | last post by:
Hello all, I was perusing the internet for information on threading when I came across this group. Since there seems to be a lot of good ideas and useful info I thought I'd pose a question. Threading is a new concept for me to implement. Here is my problem. I have a system that receives xml files and records their file locations in a database. I can potentially receive thousands,
0
8683
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...
0
8609
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9170
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9031
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8901
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
7739
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6528
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
4622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
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

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.