<commit_before>#include <iostream>
#include <future>
#include <utility>

#include "user-thread.hpp"

namespace mymain {
using namespace orks::userthread;

WorkerManager wm {4};
}

template <typename Fn>
void exec_thread(void* func_obj) {
    (*static_cast<Fn*>(func_obj))();
    delete static_cast<Fn*>(func_obj);
}

// return: std::future<auto>
template <typename Fn>
auto create_thread(Fn fn) {
    std::promise<decltype(fn())> promise;
    auto future = promise.get_future();

    // TODO INVOKE(DECAY_COPY(std::forward<F>(f)), DECAY_COPY(std::forward<Args>(args))...)
    auto fn0 = [promise = std::move(promise), fn]() mutable {
        promise.set_value(fn());
    };
    using Fn0 = decltype(fn0);
    mymain::wm.start_thread(exec_thread<Fn0>, new Fn0(std::move(fn0)));
    return future;
}

long fibo(long n) {
    std::cout << "fibo(" << n << ")" << std::endl;
    if (n == 0 || n == 1) {
        return  n;
    }
    auto future = create_thread([n]() {
        return fibo(n - 1);
    });
    auto n2 = fibo(n - 2);
    for (; future.wait_for(std::chrono::seconds(0)) != std::future_status::ready;) {
        std::cout << "wait fibo(" << n << "-1)" << std::endl;
        mymain::wm.scheduling_yield();
    }

    return n2 + future.get();
}

void fibo_main(void*) {
    std::cout << "fibo(20) must be 6765. answer: " << fibo(20) << std::endl;
}

int main() {

    mymain::wm.start_main_thread(fibo_main, nullptr);

}<commit_msg>Suppress debug output of sample/fibo.cpp<commit_after>#include <iostream>
#include <future>
#include <utility>

#include "user-thread.hpp"

namespace mymain {
using namespace orks::userthread;

WorkerManager wm {4};
}

template <typename Fn>
void exec_thread(void* func_obj) {
    (*static_cast<Fn*>(func_obj))();
    delete static_cast<Fn*>(func_obj);
}

// return: std::future<auto>
template <typename Fn>
auto create_thread(Fn fn) {
    std::promise<decltype(fn())> promise;
    auto future = promise.get_future();

    // TODO INVOKE(DECAY_COPY(std::forward<F>(f)), DECAY_COPY(std::forward<Args>(args))...)
    auto fn0 = [promise = std::move(promise), fn]() mutable {
        promise.set_value(fn());
    };
    using Fn0 = decltype(fn0);
    mymain::wm.start_thread(exec_thread<Fn0>, new Fn0(std::move(fn0)));
    return future;
}

long fibo(long n) {
    // std::cout << "fibo(" << n << ")" << std::endl;
    if (n == 0 || n == 1) {
        return  n;
    }
    auto future = create_thread([n]() {
        return fibo(n - 1);
    });
    auto n2 = fibo(n - 2);
    for (; future.wait_for(std::chrono::seconds(0)) != std::future_status::ready;) {
        // std::cout << "wait fibo(" << n << "-1)" << std::endl;
        mymain::wm.scheduling_yield();
    }

    return n2 + future.get();
}

void fibo_main(void*) {
    std::cout << "fibo(20) must be 6765. answer: " << fibo(20) << std::endl;
}

int main() {

    mymain::wm.start_main_thread(fibo_main, nullptr);

}

{'fraction_non_alphanumeric': 0.19450171821305842, 'fraction_numerical': 0.015807560137457044, 'mean_word_length': 3.56269592476489, 'pattern_counts': {'":': 0, '<': 71, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2930988', 'n_tokens_mistral': 1120, 'n_tokens_neox': 1090, 'n_words': 218}