Solved

How to implement Multi-threading

Posted on 1998-01-11
1
376 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

815 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

11 Experts available now in Live!

Get 1:1 Help Now