Question: I have a `profile.php` page with a variable `uid?=12` and i have a language bar on that is on a separate page called `lang.inc.php`:

Profile Page: 

```
<div class="langbar">
    <?php include 'inc/lang.inc.php'; ?>
</div>

```

lang.inc.php

```
<center>
    <a class="flag_USA" title="English" href="<?php echo basename($_SERVER['PHP_SELF']); ?>"><img src="css/images/us.png"></a> <span> </span> 
    <a class="flag_France" title="French" href="<?php echo basename($_SERVER['PHP_SELF']); ?>?lang=fr"><img src="css/images/fr.png"></a> <span> </span> 
    <a class="flag_dutch" title="Dutch"  href="<?php echo basename($_SERVER['PHP_SELF']); ?>?lang=de"><img src="css/images/de.png"></a> <span> </span> 
    <a class="flag_Italy" title="Italian" href="<?php echo basename($_SERVER['PHP_SELF']); ?>?lang=it"><img src="css/images/it.png"></a> <span> </span> 
    <a class="flag_Italy" title="" href="<?php echo basename($_SERVER['PHP_SELF']); ?>?lang=es"><img src="css/images/sp.png"></a> <span> </span> 
    <?php echo $_SERVER['PHP_SELF']; ?>
</center>

```

As you can see im trying to append the `?lang=fr` for example to the end of the `profile.php?uid=12` so it looks like this `profile.php?uid=12&lang=fr` but all it's doing is `profile.php?lang=fr`.

Answer: 
> 
> Isn't placing the clean up code in the destructor more or less safer than using another method to do the trick?
> 
> 
> 

The problem here is that while ExitThread (and other functions like it) is a perfect API for **C**, with C++ code, it breaks stack unwinding.

The correct solution for C++ is to make sure you do not call ExitThread (and such) in code using anything with destructors.

Problem:

```
void thread_function()
{
    raii_resource r { acquire_resource() };
    ExitThread();
    // problem: r.~raii_resource() not called
}

```

The shutdown solution:

```
void thread_function()
{
    raii_resource r { acquire_resource() };
    r.shutdown(); // release resources here
    ExitThread();
    // r.~raii_resource() still not called
}

```

The shutdown solution is not obvious at all in client code. As @stefan said, kill it with fire.

Better solution (than the Shutdown thing):

```
void thread_function()
{
    { // artificial scope where RAII objects live
        raii_resource r { acquire_resource() };
    }
    // this space does not support RAII life
    ExitThread();
}

```

RAII works fine here, but the artificial scope is not very elegant. On top, it's as inelegant as the shutdown solution (it requires a non-obvious artifice in client code).

Better (cleaner) solution:

```
template<typename F>
void run_thread(F functor)
{
    functor(); // all RAII resources inside functor; this is simple and 
               // obvious from client code
    ExitThread();
}

```
With such approach you'll need to call Shutdown in all cases where the object should be destroyed - each time when it leaves the scope. In the case of exceptions (if they are used) you'll cannot call it. Destructor will be called automatically in these cases.

"I can certainly call the destructor as well" - calling the destructor explicitly **is highly not recommended** because it will be called automatically in any case. This should be avoided except only in special cases. If you mean this code from the [tutorial](http://www.rastertek.com/dx11tut02.html):

```
System->Shutdown();
delete System;

```

then I don't see the difference because `delete System;` will call the destructor anyway.

In any case I would prefer 

```
{
    // work with System
    ...
}

```

mentioned in @utnapistim answer. I do not see any minuses in such way of coding, and also it is common way to specify scope. Even not going deep in the details of legacy `::ExitThread` you gain auto cleanup. It is possible to work with WinApi with C++ RAII technique, look for instance at my code: [multithreading](https://github.com/alexvdev/multithreading) sample project. Initial commit was bare WinAPI, and next commit introduced resource wrappers. You can compare both variants - second is much clearer, imho.