Calling an event from a thread

Now, let's use thread to call the Event class. However, before that, we have to be able to wrap more than one thread, call them together, and wait until their processes are finished. The following code block is a Wrap() function that will pack the threads:

    void Wrap(HANDLE *)    {    }    template <typename T, typename... Args>    void Wrap(      HANDLE * left,      T const & right,      Args const & ... args)      {        *left = right.Get();        Wrap(++left, args...);      }

We will call the preceding Wrap() function when we join all the threads. So, we will need another function named WaitAllThreads(), as we can see in the following piece of code:

    template <typename... Args>    void WaitAllThreads(Args const & ... args)    { HANDLE handles[sizeof...(Args)]; ...

Get Learning C++ Functional Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.