473,779 Members | 2,001 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Creating a deterministic polling thread

Hello all,

I have a little application that needs to poll a device (CAN
communications) every 10 to 15 ms otherwise the hardware buffer might
overflow when there are message burst on the bus. I would implement an
interrupt driven model, but the external device (which is connected
via USB) does not support interrupts therefore the device needs to be
polled at a specific interval. So my question is how can I implement a
"determinis tic" polling mechanism in C# (.NET)?

Currently, once the CAN communications class is instantiated it
creates a polling thread which is implemented using the
System.Threadin g.Thread class which the thread creation mechanism
looks like

// Note: All error checking was removed from sample code
ThreadStart threadDelegate = new
ThreadStart(Pol lingThreadDeleg ate);
m_PoolingThread = new Thread(threadDe legate);
m_PoolingThread .IsBackground = true;
m_PoolingThread .Priority = ThreadPriority. AboveNormal;
m_PoolingThread .Start();

Then in the method which implements the thread delegate looks like

private void PollingThreadDe legate( )
{
while ( true )
{
// FreqCnt is of type System.Diagnost ics.Stopwatch
FreqCnt.Stop();
if ( FreqCnt.Elapsed Milliseconds WorstTime )
{
WorstTime = FreqCnt.Elapsed Milliseconds;
}
FreqCnt.Reset() ;
FreqCnt.Start() ;

m_RxThreadIsAct ive = false;
m_PoolingThread .Join( (int)m_ScanMode Interval );

// Perform Read from USB interface to retrieve message from
the CAN
// device and place them in a queue

// Once all messages have been retrieved and if message count
greater
// than 0 then raise an event so the upper layer can retrieve
the
// message from the queue
}

The problem that I have with the current implementation is that
polling thread needs to be deterministic and trigger at an interval no
greater than 15 ms otherwise there is a high chance of dropping
messages during communications burst. I have tweaked the application
to the best of my ability, but instrumentation that I have (FreqCnt)
tells me the worst case timing has been in the 100 ms time frames.
>From other instrumentation generally the application drops about 2 to
3 percent of the messages which is a high rate.

I am not sure how to create the thread so it is deterministic so the
application doesn't drop any messages. Since the CAN communications
thread is not on the same thread the created the presentation layer,
which displays the information for the user, needs a delegate (correct
term?) so the process can return to the thread that created the
controls to update the controls (implemented using the MethodInvoker).

I have tried several different approaches, but none of them work
correctly. I have tried taking out the m_PoolingThread .Join statement,
but then polling thread starves the rest of the system as one could
image and especially the presentation thread. In addition, I have
tried different ThreadPriority levels though none of them help.

Any help is greatly appreciated.

Mark

Apr 11 '07 #1
13 11286
Mark,

Kind of curious, why not just create a Timer instance from the
System.Threadin g namespace. You can set the interval for 15ms and then poll
your resource then. What you have now is a little contrived, and I don't
see any real benefit to creating a separate thread just to wait for
intervals of time.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

<Lo*****@gmail. comwrote in message
news:11******** **************@ y80g2000hsf.goo glegroups.com.. .
Hello all,

I have a little application that needs to poll a device (CAN
communications) every 10 to 15 ms otherwise the hardware buffer might
overflow when there are message burst on the bus. I would implement an
interrupt driven model, but the external device (which is connected
via USB) does not support interrupts therefore the device needs to be
polled at a specific interval. So my question is how can I implement a
"determinis tic" polling mechanism in C# (.NET)?

Currently, once the CAN communications class is instantiated it
creates a polling thread which is implemented using the
System.Threadin g.Thread class which the thread creation mechanism
looks like

// Note: All error checking was removed from sample code
ThreadStart threadDelegate = new
ThreadStart(Pol lingThreadDeleg ate);
m_PoolingThread = new Thread(threadDe legate);
m_PoolingThread .IsBackground = true;
m_PoolingThread .Priority = ThreadPriority. AboveNormal;
m_PoolingThread .Start();

Then in the method which implements the thread delegate looks like

private void PollingThreadDe legate( )
{
while ( true )
{
// FreqCnt is of type System.Diagnost ics.Stopwatch
FreqCnt.Stop();
if ( FreqCnt.Elapsed Milliseconds WorstTime )
{
WorstTime = FreqCnt.Elapsed Milliseconds;
}
FreqCnt.Reset() ;
FreqCnt.Start() ;

m_RxThreadIsAct ive = false;
m_PoolingThread .Join( (int)m_ScanMode Interval );

// Perform Read from USB interface to retrieve message from
the CAN
// device and place them in a queue

// Once all messages have been retrieved and if message count
greater
// than 0 then raise an event so the upper layer can retrieve
the
// message from the queue
}

The problem that I have with the current implementation is that
polling thread needs to be deterministic and trigger at an interval no
greater than 15 ms otherwise there is a high chance of dropping
messages during communications burst. I have tweaked the application
to the best of my ability, but instrumentation that I have (FreqCnt)
tells me the worst case timing has been in the 100 ms time frames.
>>From other instrumentation generally the application drops about 2 to
3 percent of the messages which is a high rate.

I am not sure how to create the thread so it is deterministic so the
application doesn't drop any messages. Since the CAN communications
thread is not on the same thread the created the presentation layer,
which displays the information for the user, needs a delegate (correct
term?) so the process can return to the thread that created the
controls to update the controls (implemented using the MethodInvoker).

I have tried several different approaches, but none of them work
correctly. I have tried taking out the m_PoolingThread .Join statement,
but then polling thread starves the rest of the system as one could
image and especially the presentation thread. In addition, I have
tried different ThreadPriority levels though none of them help.

Any help is greatly appreciated.

Mark

Apr 11 '07 #2
On Wed, 11 Apr 2007 09:35:25 -0700, <Lo*****@gmail. comwrote:
[...]
The problem that I have with the current implementation is that
polling thread needs to be deterministic and trigger at an interval no
greater than 15 ms otherwise there is a high chance of dropping
messages during communications burst.
Windows is not a real-time OS, so there is no way to guarantee that a
thread will run within a specific interval of time. No matter what, there
will always be the possibility that your thread goes a lot longer between
run intervals than the required 15ms.

That said, in the context of the modern PC, 15ms is a pretty long time.
You might have some success in shortening your polling interval to, for
exampl5, 5ms. There are still no guarantees but it might work better.

I'm a little puzzled by the use of Join to deal with the thread blocking,
since you (if I read the code right) are joining to the current thread.
While the timeout does prevent deadlock from actually happening, it seems
like bad form to me. I would instead just use Sleep (if there should be
no way to wake the thread up early) or wait on an event with a timeout (if
you need to wake the thread up early in some situations).

I'm also puzzled by the statement that this can't be interrupt-driven, as
I was under the impression that USB controllers under Windows all use
interrupt-driven i/o. But I'm guessing that either I'm mistaken about USB
under Windows, or I don't really understand the hardware connection you're
using. I'll take as granted that simply reading in the data from the USB
port in an interrupt-driven way isn't possible.

The "right" way to fix this would probably be to write a driver for your
device. That's not really a C#/.NET question though.

Pete
Apr 11 '07 #3
On Wed, 11 Apr 2007 09:56:06 -0700, Nicholas Paldino [.NET/C# MVP]
<mv*@spam.guard .caspershouse.c omwrote:
Mark,

Kind of curious, why not just create a Timer instance from the
System.Threadin g namespace. You can set the interval for 15ms and then
poll your resource then. What you have now is a little contrived, and I
don't
see any real benefit to creating a separate thread just to wait for
intervals of time.
For what it's worth, I'd say one reason to not use the Timer class is that
if for some reason the delegate doesn't get executed during the desired
timer interval, one winds up with multiple queued timers. This can happen
if the delegate takes too long to execute (hopefully that's less likely)
or if for some reason one firing of the timer doesn't get to execute
before the next one (this is more likely, and can happen due to thread
scheduling issues or competition for thread pool threads).

Using a dedicated thread, the thread can itself figure out what the cost
of executing the timer is as well as ensuring that it doesn't waste time
executing a second time when it's just emptied the input buffer. Granted,
the code posted doesn't do any of this, but it could (and probably
should). :)

Pete
Apr 11 '07 #4
On Apr 11, 10:01 am, "Peter Duniho" <NpOeStPe...@nn owslpianmk.com>
wrote:
On Wed, 11 Apr 2007 09:35:25 -0700, <Lord...@gmail. comwrote:
[...]
The problem that I have with the current implementation is that
polling thread needs to be deterministic and trigger at an interval no
greater than 15 ms otherwise there is a high chance of dropping
messages during communications burst.

Windows is not a real-time OS, so there is no way to guarantee that a
thread will run within a specific interval of time. No matter what, there
will always be the possibility that your thread goes a lot longer between
run intervals than the required 15ms.

That said, in the context of the modern PC, 15ms is a pretty long time.
You might have some success in shortening your polling interval to, for
exampl5, 5ms. There are still no guarantees but it might work better.

I'm a little puzzled by the use of Join to deal with the thread blocking,
since you (if I read the code right) are joining to the current thread.
While the timeout does prevent deadlock from actually happening, it seems
like bad form to me. I would instead just use Sleep (if there should be
no way to wake the thread up early) or wait on an event with a timeout (if
you need to wake the thread up early in some situations).

I'm also puzzled by the statement that this can't be interrupt-driven, as
I was under the impression that USB controllers under Windows all use
interrupt-driven i/o. But I'm guessing that either I'm mistaken about USB
under Windows, or I don't really understand the hardware connection you're
using. I'll take as granted that simply reading in the data from the USB
port in an interrupt-driven way isn't possible.

The "right" way to fix this would probably be to write a driver for your
device. That's not really a C#/.NET question though.

Pete
Pete,

Thanks for the comments, just a quick few comments. I have attempted
to drop the interval from 15 to 10 to 5 and even 1 ms, though it never
helped out in the long run. While it may be true that USB does indeed
support interrupts the particular piece of hardware does not support
interrupt on the controller side. From the external device (which is
purchased from an outside vendor) it goes from a MCP2515 CAN
Controller to a uController then to the USB interface. Though the USB
interface supports hardware interrupts the uController will never
raise an interrupt from my current understanding.

I have tried both the Sleep() and Join() methods, but both methods
produce the same results. I do agree with using Join in this scenario
is bad form as I am not truly waiting for another thread to signal and
I was only using the timeout feature of the Join() method.

Another I would ask, would creating a polling mechanism in Visual C+
+ produce better results?

Mark

Apr 11 '07 #5
Nicholas,

Thanks for the feedback, unfortunately my first implementation used
a Timer and it didn't produced any better results than the current
implementation. The main reason I created a separate thread was no to
starve the GUI so it didn't seems unresponsive. Perhaps a Timer
mechanism might be better in the long run, but I couldn't get it to
work correctly.

Mark

On Apr 11, 9:56 am, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guar d.caspershouse. comwrote:
Mark,

Kind of curious, why not just create a Timer instance from the
System.Threadin g namespace. You can set the interval for 15ms and then poll
your resource then. What you have now is a little contrived, and I don't
see any real benefit to creating a separate thread just to wait for
intervals of time.

--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard .caspershouse.c om

<Lord...@gmail. comwrote in message

news:11******** **************@ y80g2000hsf.goo glegroups.com.. .
Hello all,
I have a little application that needs to poll a device (CAN
communications) every 10 to 15 ms otherwise the hardware buffer might
overflow when there are message burst on the bus. I would implement an
interrupt driven model, but the external device (which is connected
via USB) does not support interrupts therefore the device needs to be
polled at a specific interval. So my question is how can I implement a
"determinis tic" polling mechanism in C# (.NET)?
Currently, once the CAN communications class is instantiated it
creates a polling thread which is implemented using the
System.Threadin g.Thread class which the thread creation mechanism
looks like
// Note: All error checking was removed from sample code
ThreadStart threadDelegate = new
ThreadStart(Pol lingThreadDeleg ate);
m_PoolingThread = new Thread(threadDe legate);
m_PoolingThread .IsBackground = true;
m_PoolingThread .Priority = ThreadPriority. AboveNormal;
m_PoolingThread .Start();
Then in the method which implements the thread delegate looks like
private void PollingThreadDe legate( )
{
while ( true )
{
// FreqCnt is of type System.Diagnost ics.Stopwatch
FreqCnt.Stop();
if ( FreqCnt.Elapsed Milliseconds WorstTime )
{
WorstTime = FreqCnt.Elapsed Milliseconds;
}
FreqCnt.Reset() ;
FreqCnt.Start() ;
m_RxThreadIsAct ive = false;
m_PoolingThread .Join( (int)m_ScanMode Interval );
// Perform Read from USB interface to retrieve message from
the CAN
// device and place them in a queue
// Once all messages have been retrieved and if message count
greater
// than 0 then raise an event so the upper layer can retrieve
the
// message from the queue
}
The problem that I have with the current implementation is that
polling thread needs to be deterministic and trigger at an interval no
greater than 15 ms otherwise there is a high chance of dropping
messages during communications burst. I have tweaked the application
to the best of my ability, but instrumentation that I have (FreqCnt)
tells me the worst case timing has been in the 100 ms time frames.
>From other instrumentation generally the application drops about 2 to
3 percent of the messages which is a high rate.
I am not sure how to create the thread so it is deterministic so the
application doesn't drop any messages. Since the CAN communications
thread is not on the same thread the created the presentation layer,
which displays the information for the user, needs a delegate (correct
term?) so the process can return to the thread that created the
controls to update the controls (implemented using the MethodInvoker).
I have tried several different approaches, but none of them work
correctly. I have tried taking out the m_PoolingThread .Join statement,
but then polling thread starves the rest of the system as one could
image and especially the presentation thread. In addition, I have
tried different ThreadPriority levels though none of them help.
Any help is greatly appreciated.
Mark

Apr 11 '07 #6
On Wed, 11 Apr 2007 09:35:25 -0700, <Lo*****@gmail. comwrote:
[...]
// Perform Read from USB interface to retrieve message from the
CAN
// device and place them in a queue

// Once all messages have been retrieved and if message count
greater
// than 0 then raise an event so the upper layer can retrieve the
// message from the queue
One additional comment...

In replying to Nicholas's post, I realized that you always wait in your
thread for a constant amount of time. IMHO, it would be better to
subtract the time it took to process the receive from your nominal wait
interval. That is, the time inside your loop that occurs once you believe
you've emptied the input buffer but before you start waiting again. That
will ensure that the total wait time is not unduly affected by code
executing but not receiving data.

The other thing I noticed is that in your comment about receiving data,
you write "raise an event so the upper layer can retrieve the message from
the queue". It's not clear what you mean by "raise an event", since the
code isn't actually shown, but if you're using a C# event data type and
calling it to process the data, this could be the reason for the large
delays in your receiving code.

Specifically, when you "raise an event" in .NET using the event/delegate
paradigm, the event is handled on the thread that raised the event in the
first place (usually by calling an "OnXXX" method that runs the event
handlers).

Your receiving thread should *only* be receiving and copying the data
somewhere. Once the data is in a queue, then some means of signaling to
another thread to do the actual processing can be used. This might be by
using BeginInvoke on your UI form or some control on the form, if the
"actual processing" is primarily for user output, or you might have
another thread dedicated to actually processing the data, if you're doing
something more complex with it (like writing it to a file or something).

The problem here is the ambiguity in the use of the word "event" when it
comes to .NET programming. It could have either the traditional Windows
API meaning related to an "event handle", or it could have the new .NET
meaning related to events and their event handlers (special delegates
called when you process the event). Since you didn't post the actual code
for that, we don't know which one of those meanings you're using when you
write "event".

Pete
Apr 11 '07 #7
I would tend to shy away from a Timer based approach - 15 milliseconds isn't
very long, and it's very easy to end up missing a timer interval. I'm not
even sure if any timers (other than the MultiMedia Win32 Timers) are
accurate at resolutions smaller than 60 milliseconds.

I would lean towards a dedicated thread that is continually in a
While(!shutdown ) loop, continually polling data. and using a SpinWait to
wait between polls. You may also be forced to play some thread Priority
games (which are very dangerous, and tough to get right), in order to make
sure you don't miss any polling cycles.

When you pull data out of the USB buffer, you'll want to put it into your
own buffer. You'll also want to tickel an Event of some sort (probably a
ManualResetEven t) saying you've got data. This will allow other threads to
wake up and do something usefull with the data.

Joe Duffy has talked a little bit about how all this works at:
http://www.bluebytesoftware.com/blog...4b8f3d1a1.aspx

--
Chris Mullins, MCSD.NET, MCPD:Enterprise , Microsoft C# MVP
http://www.coversant.com/blogs/cmullins

<Lo*****@gmail. comwrote in message
news:11******** **************@ y80g2000hsf.goo glegroups.com.. .
Hello all,

I have a little application that needs to poll a device (CAN
communications) every 10 to 15 ms otherwise the hardware buffer might
overflow when there are message burst on the bus. I would implement an
interrupt driven model, but the external device (which is connected
via USB) does not support interrupts therefore the device needs to be
polled at a specific interval. So my question is how can I implement a
"determinis tic" polling mechanism in C# (.NET)?

Currently, once the CAN communications class is instantiated it
creates a polling thread which is implemented using the
System.Threadin g.Thread class which the thread creation mechanism
looks like

// Note: All error checking was removed from sample code
ThreadStart threadDelegate = new
ThreadStart(Pol lingThreadDeleg ate);
m_PoolingThread = new Thread(threadDe legate);
m_PoolingThread .IsBackground = true;
m_PoolingThread .Priority = ThreadPriority. AboveNormal;
m_PoolingThread .Start();

Then in the method which implements the thread delegate looks like

private void PollingThreadDe legate( )
{
while ( true )
{
// FreqCnt is of type System.Diagnost ics.Stopwatch
FreqCnt.Stop();
if ( FreqCnt.Elapsed Milliseconds WorstTime )
{
WorstTime = FreqCnt.Elapsed Milliseconds;
}
FreqCnt.Reset() ;
FreqCnt.Start() ;

m_RxThreadIsAct ive = false;
m_PoolingThread .Join( (int)m_ScanMode Interval );

// Perform Read from USB interface to retrieve message from
the CAN
// device and place them in a queue

// Once all messages have been retrieved and if message count
greater
// than 0 then raise an event so the upper layer can retrieve
the
// message from the queue
}

The problem that I have with the current implementation is that
polling thread needs to be deterministic and trigger at an interval no
greater than 15 ms otherwise there is a high chance of dropping
messages during communications burst. I have tweaked the application
to the best of my ability, but instrumentation that I have (FreqCnt)
tells me the worst case timing has been in the 100 ms time frames.
>>From other instrumentation generally the application drops about 2 to
3 percent of the messages which is a high rate.

I am not sure how to create the thread so it is deterministic so the
application doesn't drop any messages. Since the CAN communications
thread is not on the same thread the created the presentation layer,
which displays the information for the user, needs a delegate (correct
term?) so the process can return to the thread that created the
controls to update the controls (implemented using the MethodInvoker).

I have tried several different approaches, but none of them work
correctly. I have tried taking out the m_PoolingThread .Join statement,
but then polling thread starves the rest of the system as one could
image and especially the presentation thread. In addition, I have
tried different ThreadPriority levels though none of them help.

Any help is greatly appreciated.

Mark

Apr 11 '07 #8
On Wed, 11 Apr 2007 10:35:37 -0700, <Lo*****@gmail. comwrote:
[...]
Another I would ask, would creating a polling mechanism in Visual C+
+ produce better results?
Doubtful. The timing limitations here are inherent to Windows. There's a
little overhead to running .NET code, but not much.

Please see my other follow-up reply, for other possible improvements to
your design. The more I think about it, the more I don't see why you
should sometimes see delays of as much as 100ms, unless you're causing
those delays yourself in the code that handles the data after it's been
received. 100ms is a LOT of time for a modern computer. A HUGE amount of
time. :)

By the way, based on your comment that you tried changing the thread
priority, I am making the assumption that your data receiving thread is
not being hindered by other threads running on the computer (in your
process or in other processes) that use up their full time quanta.
Assuming such other threads would be running at a lower priority than the
priority you tried then at most only one should be able to monopolize the
CPU between your own thread's execution, and the thread quantum is much
much smaller than the tens or hundreds of millisecond delays you're seeing.

That is, it doesn't sound like your process is being interfered with by
other processes, and is instead intefering with itself all by itself. But
if my assumptions are wrong, that would be something to consider as well.
Again, since Windows isn't a real-time OS, you can always run into a
situation where other processes get in the way of your own process getting
CPU time exactly when you want it.

Pete
Apr 11 '07 #9
Mark,

Were you using a Timer from the System.Windows. Forms namespace (which I
think is the case because you said you were starving the UI) or from the
System.Threadin g namespace? If you used the latter, then the timer event
should be fired on a non UI thread.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

<Lo*****@gmail. comwrote in message
news:11******** **************@ d57g2000hsg.goo glegroups.com.. .
Nicholas,

Thanks for the feedback, unfortunately my first implementation used
a Timer and it didn't produced any better results than the current
implementation. The main reason I created a separate thread was no to
starve the GUI so it didn't seems unresponsive. Perhaps a Timer
mechanism might be better in the long run, but I couldn't get it to
work correctly.

Mark

On Apr 11, 9:56 am, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guar d.caspershouse. comwrote:
>Mark,

Kind of curious, why not just create a Timer instance from the
System.Threadi ng namespace. You can set the interval for 15ms and then
poll
your resource then. What you have now is a little contrived, and I don't
see any real benefit to creating a separate thread just to wait for
intervals of time.

--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard .caspershouse.c om

<Lord...@gmail .comwrote in message

news:11******* *************** @y80g2000hsf.go oglegroups.com. ..
Hello all,
I have a little application that needs to poll a device (CAN
communications) every 10 to 15 ms otherwise the hardware buffer might
overflow when there are message burst on the bus. I would implement an
interrupt driven model, but the external device (which is connected
via USB) does not support interrupts therefore the device needs to be
polled at a specific interval. So my question is how can I implement a
"determinis tic" polling mechanism in C# (.NET)?
Currently, once the CAN communications class is instantiated it
creates a polling thread which is implemented using the
System.Threadin g.Thread class which the thread creation mechanism
looks like
// Note: All error checking was removed from sample code
ThreadStart threadDelegate = new
ThreadStart(Pol lingThreadDeleg ate);
m_PoolingThread = new Thread(threadDe legate);
m_PoolingThread .IsBackground = true;
m_PoolingThread .Priority = ThreadPriority. AboveNormal;
m_PoolingThread .Start();
Then in the method which implements the thread delegate looks like
private void PollingThreadDe legate( )
{
while ( true )
{
// FreqCnt is of type System.Diagnost ics.Stopwatch
FreqCnt.Stop();
if ( FreqCnt.Elapsed Milliseconds WorstTime )
{
WorstTime = FreqCnt.Elapsed Milliseconds;
}
FreqCnt.Reset() ;
FreqCnt.Start() ;
m_RxThreadIsAct ive = false;
m_PoolingThread .Join( (int)m_ScanMode Interval );
// Perform Read from USB interface to retrieve message from
the CAN
// device and place them in a queue
// Once all messages have been retrieved and if message count
greater
// than 0 then raise an event so the upper layer can retrieve
the
// message from the queue
}
The problem that I have with the current implementation is that
polling thread needs to be deterministic and trigger at an interval no
greater than 15 ms otherwise there is a high chance of dropping
messages during communications burst. I have tweaked the application
to the best of my ability, but instrumentation that I have (FreqCnt)
tells me the worst case timing has been in the 100 ms time frames.
From other instrumentation generally the application drops about 2 to
3 percent of the messages which is a high rate.
I am not sure how to create the thread so it is deterministic so the
application doesn't drop any messages. Since the CAN communications
thread is not on the same thread the created the presentation layer,
which displays the information for the user, needs a delegate (correct
term?) so the process can return to the thread that created the
controls to update the controls (implemented using the MethodInvoker).
I have tried several different approaches, but none of them work
correctly. I have tried taking out the m_PoolingThread .Join statement,
but then polling thread starves the rest of the system as one could
image and especially the presentation thread. In addition, I have
tried different ThreadPriority levels though none of them help.
Any help is greatly appreciated.
Mark


Apr 11 '07 #10

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

Similar topics

44
2376
by: Charles Law | last post by:
Hi guys. I'm back on the threading gig again. It's the age-old question about waiting for something to happen without wasting time doing it. Take two threads: the main thread and a worker thread. The worker thread is reading the serial port, waiting for something to happen (a service request). When it does it raises an event. Of course, the event is executed on the worker thread. The idea is that when the event is raised, the handler...
0
1507
by: Sreedharan | last post by:
Hello everyone, I am a VC++ programmer. When i develop a multi-threaded application in C++, I prefer to use worker thread, so that the main thread and worker thread can communicate using messages.(i will prefer to use PostMessage than SendMessage API in order to avoid any dead locks ) I prefer to post messages to a thread , instead using call back functions(passing pointer to another thread's function.)
6
2348
by: darklupine | last post by:
I'm working on a project for a class at school. In order to complete the project, I have to create a new thread, but I'm not overly certain on how to do so. I have it coded, but it still throws an error, and I can't figure out why it is doing so. The create line reads: pthread_create(&thread1, NULL, (void *)&CourNet::recieve, NULL); CourNet is my class name, and recieve is the function I'll be calling.
9
2986
by: =?Utf-8?B?YmJn?= | last post by:
Hi all, I read somewhere "using kernel stuff in thread is not good.." if ManualResetEvent object is created in thread but not actually used, will it affect performance? Bob
1
3154
by: Alexander Dronov | last post by:
Hello guys. I have a polling thread in my application. It calls GetMyStructs method with interval 1,5 seconds. // ... SqlConnection _sqlConnection = new SqlConnection(); _sqlConnection.ConnectionString = string.Format("Server = {0}; User Id = {1}; pwd = {2}; Database = {3}; Pooling = false; MultipleActiveResultSets = true", Instance, Login, Password, Database); // OK _activateAppRole = new SqlCommand("EXEC...
0
9632
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
9471
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
10302
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
10136
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...
0
8958
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
7478
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
5501
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4036
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
3631
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.