Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

working with THREAD's 1

Status
Not open for further replies.

zigular

Technical User
Jun 29, 2004
18
DE
hello at all professional thread-user!

i've implemented a single thread in my appl to grab some data from a sensor. in the thread i call a simple visualisation for each of the data packages.

for creating the thread i use the common way of doing like descriped in visual c++ in 21 days or similar easy books.

for better discussion i just paste in the main lines:

// (A) Worker-Thread starten und Zeiger auf struct GThreadData übergeben
_thread = AfxBeginThread(GrabberThread, (LPVOID) _threadData, liPriority);

// (B) Handle für Thread holen
HANDLE hThread = _thread->m_hThread;
// auf Absterben des Threads warten
::WaitForSingleObject(hThread, INFINITE);

now to my problem. both - starting and stopping - i've implemented in a function called SuspendSensor and use a simple BOOL to start and to stop. (A) seems to be ok, cause the appl does what it should do. (B) doesn't work at all. (B) i've also implemented in the OnExit funktion, but i think it will be overwrited by some other mechanisms from MFC while stopping the whole appl. if i call the SuspendSensor funtion with FALSE in the argument (that means stop the thread) during the running appl my appl crashs.

what is wrong? are there other ways to force the program to stop a thread such as i have created?

your greenhorn in programming with threads
hilmar :)
 
(B) isn't stopping the thread, it is waiting for it to be stopped. The thread must stop itself, either by returning from the thread function or by calling AfxEndThread.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top