开发者

OS independent threading in C++?

开发者 https://www.devze.com 2023-01-31 00:30 出处:网络
Is it possible to implement OS independ开发者_JAVA技巧ent threading model of User Level Threads (ULT) in C/C++? In other words, can we break down a process logically into ULTs and dynamically make swi

Is it possible to implement OS independ开发者_JAVA技巧ent threading model of User Level Threads (ULT) in C/C++? In other words, can we break down a process logically into ULTs and dynamically make switches in between them?


Boost.Thread offers a fair amount of abstraction for cross-platform threading.


Just use POSIX threads. There's a reasonably conformant implementation for Windows if you need to support Windows.


OpenMP is a nice way to handle threads for many common use cases.


In C, one somewhat portable (it requires POSIX) user-level threading library is GNU Pth. It uses cooperation instead of preemption, and implements per-thread stack and other structures in user space. As expected, this will not provide the same performance characteristics as OS-level threading. However, it does provide some of the same abstractions.


On windows 7 there is a way to implement your own User Mode Scheduler: http://msdn.microsoft.com/en-us/library/dd627187%28v=vs.85%29.aspx

This is basecally an API to make a User Mode Threads using a User Mode Scheduler and the best thing is opening process explorer and see Kernel Time 0.

Hwever I know people who implemented successfully the UMS but the microsoft reported some errors on the api . . .


You may have a look at ZThread is a cross platform c++ library.

Thinking in c++ vol 2 uses this library to explain multi-threading application.

0

精彩评论

暂无评论...
验证码 换一张
取 消