Skip to content

Commit

Permalink
#0: Remove ThreadManager from api
Browse files Browse the repository at this point in the history
  • Loading branch information
nhuang-tt committed Feb 27, 2025
1 parent 72aee0d commit 7092f25
Showing 1 changed file with 0 additions and 46 deletions.
46 changes: 0 additions & 46 deletions tt_metal/api/tt-metalium/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,52 +31,6 @@ struct DefinesHash {
size_t operator()(const std::map<std::string, std::string>& c_defines) const;
};

inline std::vector<std::string> strsplit(std::string input, char delimiter) {
std::vector<std::string> result = {};
std::stringstream ss(input);

while (ss.good()) {
std::string substr;
getline(ss, substr, delimiter);
result.push_back(substr);
}
return result;
}

// A simple thread manager that joins all threads and rethrows the first caught exception
// instead of letting the program terminate.
class ThreadManager {
public:
template <typename Func, typename... Args>
void start(Func&& func, Args&&... args) {
threads.emplace_back(std::thread([=]() {
try {
func(args...);
} catch (...) {
std::lock_guard<std::mutex> lock(exceptionMutex);
exceptions.push_back(std::current_exception());
}
}));
}

void join_and_rethrow() {
for (auto& thread : threads) {
if (thread.joinable()) {
thread.join();
}
}

if (!exceptions.empty()) {
std::rethrow_exception(exceptions.front());
}
}

private:
std::vector<std::thread> threads;
std::vector<std::exception_ptr> exceptions;
std::mutex exceptionMutex;
};

template <typename E, std::enable_if_t<std::is_enum<E>::value, bool> = true>
auto underlying_type(const E& e) {
return static_cast<typename std::underlying_type<E>::type>(e);
Expand Down

0 comments on commit 7092f25

Please sign in to comment.