Solved

How to implement Multi-threading

Posted on 1998-01-11
1
361 Views
Last Modified: 2008-03-03
I am building an SDI MFC application which has a user interface class and a database class.  I am also using a virtual device driver to access the network interface card in a promiscuous mode.  The packet monitor function makes a call to DeviceIoControl to retrieve any packets that arrive at the NIC.  Since at any moment, there may or may not be a packet to read, I call GetOverlappedResult which waits indefinetly for a packet arrival.  This, of course locks up the many windows GUI messages I am using to update the GUI, since windows is in a single thread mode and I am blocking any other progress.  How should I implement this function to run under a separate thread and still have the packet results available to the other thread?

Thanks
0
Comment
Question by:bknouse
1 Comment
 
LVL 15

Accepted Solution

by:
Tommy Hui earned 100 total points
ID: 1178138
You need to create a function that matches this prototype:

  LRESULT MyThreadedFunc(LPVOID param);

Then you can use AfxBeginThread(MyThreadedFunc, anyParam);

You also need to structure your code so that it is doing something like

  {
    while (TRUE)
    {
      GetOverlappedResult(...);
      /* communicated with program that result is ready */
    }
  }


0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now