80 DISPENSO_REQUIRES(OnceCallableFunc<F>)
82 schedule(std::forward<F>(f), ForceQueuingTag());
92 DISPENSO_REQUIRES(OnceCallableFunc<F>)
98 auto done = std::make_shared<std::atomic<bool>>(
false);
99 std::thread thread([f = std::move(f), done]() {
101 done->store(
true, std::memory_order_release);
103 getTracker()->add(std::move(thread), std::move(done));
126 struct ThreadTracker {
131 std::shared_ptr<std::atomic<bool>> done;
135 std::vector<Entry> entries_;
137 void add(std::thread&& t, std::shared_ptr<std::atomic<bool>> done)
138 DISPENSO_NO_THREAD_SAFETY_ANALYSIS {
144 std::vector<std::thread> finished;
146 std::lock_guard<std::mutex> lk(mtx_);
147 for (
size_t i = 0; i < entries_.size();) {
148 if (entries_[i].done->load(std::memory_order_acquire)) {
149 finished.push_back(std::move(entries_[i].thread));
150 entries_[i] = std::move(entries_.back());
156 entries_.push_back(Entry{std::move(t), std::move(done)});
158 for (std::thread& thread : finished) {
164 void joinAll() DISPENSO_NO_THREAD_SAFETY_ANALYSIS;
167 DISPENSO_DLL_ACCESS static ThreadTracker* getTracker();