c++ - Terminating Qt worker thread during program shutdown -


i use qt 4.8.6, ms visual studio 2008, windows 7. i've created gui program. contains main gui thread , worker thread (i have not made qthread subclass, way), makes synchronous calls 3rd party dll functions. these functions rather slow. qtcpserver instance under worker thread. worker class contains qtcpserver , dll wrapper methods.

i know quit() preferred on terminate(), don't wanna wait minute (because of slow dll functions) during program shutdown. when try terminate() worker thread, notice warnings stopping qtcpserver thread. correct way of process shutdown?

unless there overriding reason so, should not attempt terminate threads user code @ process-termination.

if there no such reason, call os process termination syscall, eg. exitprocess(0). os can, , will stop process threads in state before releasing process resources. user code cannot that, , should not try terminate threads, or signal them self-terminate, unless absolutely necessary.

attempting 'clean up' user code sounds 'nice', (aparrently), expensive luxury pay code, testing , maintenance.

that is, if customers don't stop buying app because pissed off taking long shut down.

the os @ stopping threads , cleaning up. it's had endless thousands of hours of testing during development , decades of life in wild problems process termination have become aparrent , got fixed. not close flags, events etc. struggle stop threads running on core without benefit of interprocessor driver.

there surely times when have resort user code stop threads. if need stop them before process termination, or need close db connection, flush file @ shutdown, deal interprocess comms or issues, have resort of approaches suggested in other answers.

if not, don't try duplicate os functionality in name of 'niceness'. ask terminate process. can warm, fuzzy feeling when app shuts down immedately while other developers still struggling implement 'shutdown' progress bars or trying explain customers why have 15 zombie apps still running.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -