forked from Alepha/Alepha
Thread Group (More needs to be done, but this is a start).
This commit is contained in:
46
ThreadGroup.h
Normal file
46
ThreadGroup.h
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
static_assert( __cplusplus > 2020'99 );
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Alepha/Alepha.h>
|
||||||
|
|
||||||
|
#include "Thread.h"
|
||||||
|
|
||||||
|
namespace Alepha::Hydrogen ::detail:: ThreadGroup_m
|
||||||
|
{
|
||||||
|
inline namespace exports
|
||||||
|
{
|
||||||
|
class ThreadGroup;
|
||||||
|
}
|
||||||
|
|
||||||
|
class exports::ThreadGroup
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
std::vector< std::unique_ptr< Thread > > threads;
|
||||||
|
|
||||||
|
public:
|
||||||
|
template< typename Function >
|
||||||
|
void
|
||||||
|
addThread( Function function )
|
||||||
|
{
|
||||||
|
// TODO: Exception handler wrapper
|
||||||
|
// TODO: lockstep start wrapper?
|
||||||
|
threads.push_back( std::make_unique< Thread >( std::forward< Function >( function ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
join()
|
||||||
|
{
|
||||||
|
// TODO: Handle errors....
|
||||||
|
for( auto &thread: threads )
|
||||||
|
{
|
||||||
|
thread->join();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Alepha::Hydrogen::inline exports::inline ThreadGroup_m
|
||||||
|
{
|
||||||
|
using namespace detail::ThreadGroup_m::exports;
|
||||||
|
}
|
Reference in New Issue
Block a user