关于pthread和win32线程 [英] Regarding pthreads and win32 threads

查看:234
本文介绍了关于pthread和win32线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
Iam正在做一个术语项目,以测量Windows和Linux中多线程的性能.
Iam在用户线程和内核线程之间感到困惑.我在一篇文章中读过线程创建,线程终止和线程调度是由ubuntu Linux和Windows 7中的OS处理的. 当Iam调用pthread_create()函数时,OS(Linux)是在创建线程还是posix库?
OS(linux)可以创建用户线程和内核线程吗?

Windows,使用WIN32线程的Iam,WIN32是API还是库?
与linux中的混乱相同.

谁能在这些事情上给我任何清晰的建议.

Hi All,
Iam doing a term project to measure the performance of multithreading in windows and linux.
Iam confused between user threads and kernel threads.I have read, in an article thread creation, thread termination and thread scheduling is handled by OS in ubuntu Linux and in windows 7.
when Iam calling pthread_create() function, is OS(Linux) creating thread or the posix library?
OS(linux) can create user threads and kernel threads?

Windows, Iam using WIN32 threads, Is WIN32 is API or an library?
same confusion as in linux.

Can any one suggest me any material with clarity on these things.

推荐答案

API ==应用程序编程接口
您似乎很困惑……API是库的公共接口. winapi是win32库的公共接口. STD C标头集是std c库的公共接口(API),依此类推...每个程序都是一堆使用库的代码.您可以将操作系统视为一组库-每个库都有其自己的接口(API).

线程同步的最有效方法始终是使用操作系统本机提供的最合适的线程同步原语.请注意,在一个操作系统中发现的一项功能可能在另一操作系统中不存在.因此,使用跨平台库(如pthreads)可能不会给您带来有意义的结果.例如,在Win32中,模拟条件变量+互斥(在pthread api中存在)是很痛苦的.
在两个不同的操作系统上,针对多重读取问题的最佳解决方案可能完全不同.

从这一点出发,您应该自己继续使用Google进行研究.在进行谷歌搜索时,请不要忘记您可能不是第一个为此创建基准的人.我还要指出,创建这样的基准需要在每个平台上都有线程方面的经验,因为您必须非常了解每个同步原语(和调度问题)的优缺点,并且必须猜测某些多线程的良好解决方案.问题-对于初学者来说,这不是游戏.
API == Application Programming Interface
You seem to be quite on the confused side... An API is a public interface to a library. The winapi is a public interface to the win32 libraries. The STD C header set is a public interface (API) to the std c libraries, and so on... Every program is a bunch of code that uses libraries. You can treat an operating system as a set of libraries - each library having its own interface (API).

The most effective way of thread synchronization is always using the most suitable thread synchronization primitives offered natively by the OS. Note that one feature found in one OS might not be present in another OS. For this reason using a cross-platform library (like pthreads) might not give you meaningful results. For example simulating a condition variable+mutex (present in pthread api) has been painful in Win32.
The optimal solution to a multit-hreading problem can be completely different on 2 different OSes.

From this point you should continue your research by yourself using google. While googling don''t forget that you are probably not the first to create benchmarks for this purpose. I would also note that creating such a benchmark requires experience with threading on each platform because you have to know the strength and weakness of each synchronization primitive (and scheduling problems) quite well and have to have a guess on good solutions to certain multi-threading problems - its not a game for a beginner in threading.


这篇关于关于pthread和win32线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆