Threading lambda functions I've created this very small header that allows direct creation of threads from lambdas.
I can't find anything else similar on the net so I want to know whether there are any problems with this that I have not thought of. It is based on tinythread++, but can easily be altered to work with pthread or other threading libraries that can take a void (void*) (or void* (void*)) function and a void* argument for the function to start a thread. Note that this implementation is assuming limited C++0x/11 support, i.e. just lambdas.

#include "tinythread.h"

namespace lthread {
    /// implementation details - do not use directly
    namespace impl {
        template&lt;typename Func&gt;
        void use_function_once(void* _f) {
            const Func* f = (const Func*)_f;
            (*f)();
            delete f; // delete - no longer needed
        }
        template&lt;typename Func&gt;
        void use_function(void* _f) {
            const Func* f = (const Func*)_f;
            (*f)();
        }
    }

    /// Creates a thread based on a temporary function.
    /// Copies the function onto the heap for use outside of the local scope, removes from the heap when finished.
    template&lt;typename Func&gt;
    tthread::thread* new_thread(const Func&amp; f) {
        Func* _f = new Func(f); // copy to heap
        return new tthread::thread(&amp;impl::use_function_once&lt;Func&gt;,(void*)_f);
    }

    /// Creates a thread based on a guaranteed persistent function.
    /// Does not copy or delete the function.
    template&lt;typename Func&gt;
    tthread::thread* new_thread(const Func* f) {
        return new tthread::thread(&amp;impl::use_function&lt;Func&gt;, (void*)f);
    }
}


Example usage:

size_t a = 1;
size_t b = 0;
tthread::thread* t = lthread::new_thread([&amp;] () {
    std::cout &lt;&lt; "I'm in a thread!\n";
    std::cout &lt;&lt; "'a' is " &lt;&lt; a &lt;&lt; std::endl;
    b = 1;
});
t-&gt;join();
std::cout &lt;&lt; "'b' is " &lt;&lt; b &lt;&lt; std::endl;
delete t;
surely you can just use std::function&lt;void()&gt; instead of templating on the function type?
capturing by reference can go horribly wrong. It's not a bug in your library, just an observation ...

tthread::thread* startthread(size_t a, size_t b)
{
    return lthread::new_thread([&amp;] ()
        {
            std::cout &lt;&lt; "I'm in a thread!\n";
            std::cout &lt;&lt; "'a' is " &lt;&lt; a &lt;&lt; std::endl;
            b = 1;
        }
        );
}

int main()
{
    tthread::thread *t = startthread(1,2);
    t-&gt;join();
    delete t;
}

use_function_once is vulnerable to the function call throwing an exception: you should probably assign it to a smart pointer before calling, and lose the explicit delete.
that overload of new_thread also has a problem if either new or tthread::thread can throw: it will leak the heap-allocated Func. You can fix this with a smart pointer too.