#pragma once

#include <unordered_map>
#include <memory>
#include <thread>
#include <mutex>
#include <atomic>
#include <vector>

class ThreadCollection
{
public:
	bool add(std::unique_ptr<std::thread> thread);

	void joinAndClearAll();

	void markForRemoval(std::thread::thread::id inputId);

	void removeMarked();

	std::size_t size() const;

private:
	void _remove(std::thread::thread::id inputId);

	mutable std::mutex mMutex;
	std::atomic<bool> mAccepting{ true };

	std::vector<std::thread::thread::id> mMarkedForRemoval;
	std::unordered_map<std::thread::thread::id, std::unique_ptr<std::thread> > mThreads;
};