Home > Software engineering >  Questions about MFC multithreaded programming
Questions about MFC multithreaded programming

Time:10-09

My program is divided into two parts:
1. The above data from the device,
2. The collected data for processing, drawing,
Because data processing more more troublesome, my idea is to collect data separately for a thread, and then open a thread processing data, data acquisition fast until picking, data processing can take your time,
I use MFC, for multithreaded don't know, but also more urgent, this kind of circumstance is open two worker threads,
If someone has a similar example is better, thank you very much,

CodePudding user response:

Example multithreading is easy, there are many online

CodePudding user response:

What do you think can, just gathering thread to handle need to exchange data between threads, can use a queue, etc

CodePudding user response:

In so doing can definitely, if the collection of information in several as moderator said in the queue, about queue http://www.cnblogs.com/mfryf/archive/2012/08/09/2629992.html remember locking,
In fact if you fast data acquisition, and processing don't try so hard, it can also be a thread

CodePudding user response:

A thread to collect images, then there is A need to deal with image, to open A thread B, was introduced into the image on A thread to deal with B

CodePudding user response:

Generally speaking, a thread is needed to collect data, and data processing depends on the actual situation, if is complicated but it doesn't take, there is no need to open a thread, if it is very time consuming, that is about to start threads,
Data processing without time-consuming, then can be finished on the acquisition of the thread, can also be put into the queue and then in the main thread processing, can also send a message to the main window, processing processing data in the message)
If it is a very time consuming, use a separate thread to handle, when the need to pay attention to thread synchronization problem, this is the place where the most important thing to notice,

As for how to create a thread, is the most basic CreateThread (), to search on the net a lot

CodePudding user response:

reference 5 floor JSZJ reply:
in general, a thread is needed to collect data, and data processing depends on the actual situation, if is complicated but it doesn't take, there is no need to open a thread, if it is a very time consuming, it is about to start a thread,
Data processing without time-consuming, then can be finished on the acquisition of the thread, can also be put into the queue and then in the main thread processing, can also send a message to the main window, processing processing data in the message)
If it is a very time consuming, use a separate thread to handle, when the need to pay attention to thread synchronization problem, this is the place where the most important thing to notice,

As for how to create a thread, is the most basic CreateThread (), to search on the net a lot

To my data processing is very time consuming, because many matrix operations, so I don't want to affect my data gathering speed, so this kind of circumstance commonly is done with multithreading to solve of, or any other method,

CodePudding user response:

Since the time consuming, then use thread processing, thread the basic flow is roughly as follows:

Bool bRuning;
DWORD threadEntry (LPVOID LPVOID)
{
While (thus)
{
. ; Do yourself work here
Sleep (1);
}
return 0;
}

BOOL CMyDialog: : OnInitDialog ()
{
CDialog: : OnInitDialog ();

SECTURITY_ATTRIBUTE sa;
Memset (& amp; Sa, 0, sizeof (sa));
Sa. NLength=sizeof (sa);
DWORD threadId;
BRuning=true;
HANDLE hThread=CreateThread (& amp; Sa, 0, (LPTHREAD_START_ROUTINE) theadEntry, (LPVOID) m_hWnd, & amp; TheadId);
return TRUE;
}
  • Related