[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Calling Exit () functio within a Multithreaded Environment

Posted on 2008-06-13
2
Medium Priority
?
295 Views
Last Modified: 2013-12-04
I am writing a multithreaded Windows application in C using Visual Studio.net.  In certain situations, my application needs to shut down immediately, and I was thinking of calling the exit() function within the main thread.  Will this have any adverse effects on the system it is running on?  Are there any safer methods that I can use (remembering that it needs to shut down as quickly as possible)?
0
Comment
Question by:jtrades
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 53

Accepted Solution

by:
Infinity08 earned 500 total points
ID: 21781706
Calling exit (in Windows) will end the process after doing some basic cleanup (like stopping the threads etc.). There's no adverse effects on the system (other than the fact that the process won't be running any more ;) ).


I would however recommend to shut down your threads properly, or you might halt them in the middle of something which might or might not be bad (depending on what the threads do).
0
 
LVL 46

Assisted Solution

by:Kent Olsen
Kent Olsen earned 500 total points
ID: 21781890
Hi jtrades,

Infinity's right.  :)

Keep in mind the differences between a program and a thread.  A program is just what you think it is -- you run Notepad.exe, MyApplication.exe, etc. and the program occupies a memory space, uses system resources, and interacts with the user and the operating system.

A thread is a place (function or routine ) within a program that is that is identified to the operating system as another place for the CPU to execute code, outside of the main program.

exit () terminates the program.  It doesn't know about or care about threads, so results in the fastest shutdown.  The underlying operating system certainly knows about the program's threads and will take whatever steps necessary to dequeue the threads prior to the program's termination.

So the issue is cleanup.  If you've got a multi-threaded program where the threads are playing chess against each other, you may not care how gracefully the threads clean up.  But if you've got a multi-threaded program that is essentially a database manager, you'd better clean up gracefully to ensure that you're not in the middle of a series of write operations as writing only part of the series would result in a corrupt database.


Good Luck,
Kent
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Step by step guide to Clean and Sort your windows registry! Introduction: Always remember: A Clean registry = Better performance = Save your invaluable time In this article we're going to clear our registry manually! Yes, manually! The e…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

649 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