Skip to content
This repository has been archived by the owner on Jun 23, 2021. It is now read-only.
/ win_thread Public archive

Implementation of std::thread using WinAPI.

License

Notifications You must be signed in to change notification settings

RIscRIpt/win_thread

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

win_thread

Implementation of std::thread using WinAPI.

Example of usage

#include <iostream>
#include <win_thread/win_thread.h>

void pow(double a, double b, double &c) {
    using namespace std::chrono_literals;

    c = std::pow(a, b);

    // std::this_thread::get_id();
    std::cout << "pow thread id: " << win::this_thread::get_id() << '\n';

    // std::this_thread::yield();
    win::this_thread::yield();

    // std::this_thread::sleep_for();
    win::this_thread::sleep_for(0.5s);

    // std::this_thread::sleep_until();
    win::this_thread::sleep_until(std::chrono::system_clock::now() + 0.5s);
}

int main() {
    std::ios::sync_with_stdio(false);

    unsigned int n = win::thread::hardware_concurrency();
    std::cout << n << " concurrent threads are supported.\n";

    double result;
    win::thread t(pow, 2, 3, std::ref(result));
    std::cout << "pow thread id: " << t.get_id() << '\n';
    t.join();

    win::thread lambda_thread([result]() {
        std::cout << "2**3 == " << result << '\n';
    });
    lambda_thread.join();

    return 0;
}

Output:

8 concurrent threads are supported.
pow thread id: <id>
pow thread id: <id>
2**3 == 8

Releases

No releases published

Packages

 
 
 

Languages