Skip to content

Instantly share code, notes, and snippets.

@stevemk14ebr
Last active December 15, 2020 19:15
Show Gist options
  • Save stevemk14ebr/84f2f3a51b7e0b0530af150133b181a0 to your computer and use it in GitHub Desktop.
Save stevemk14ebr/84f2f3a51b7e0b0530af150133b181a0 to your computer and use it in GitHub Desktop.
moodycamel::ConcurrentQueue<std::wstring> worker_queue;
std::wstring ascii = L"abcdefghijklmnopqrstuvwxyz._-0123456789";
void handle_comb()
{
while (true) {
std::wstring attempt;
if (!worker_queue.try_dequeue(attempt)) {
continue;
}
... do stuff ...
}
}
void add_work_item(const std::wstring& item)
{
bool queued = false;
do {
queued = worker_queue.try_enqueue(item);
} while(!queued);
}
int main()
{
std::vector<std::thread> threads;
for (int i = 0; i < 14; i++) {
threads.push_back(std::thread(handle_comb));
}
for (int i = 0; i < 16; i++) {
for (auto&& i : iter::combinations_with_replacement(ascii, i)) {
for (auto&& j : iter::permutations(i)) {
std::wstring attempt;
attempt.reserve(j.size());
for (auto c : j) {
attempt.push_back(c);
}
add_work_item(attempt);
}
}
}
for (auto& thread : threads) {
thread.join();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment