关于线程的查询 [英] query regarding threads

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

问题描述

如果(例如)我们有一个线程,线程会做什么?我们可以在线程外执行代码吗?



最后,哪些低级操作系统特定函数用于实现std :: thread / boost :: thread / pthread在Windows中,更灵活,更简单:低级函数或类。

if (e.g) we have one thread, what will thread do? and can we execute the code outside the thread?

Lastly, which low-level OS specific functions are used to implement std::thread/boost::thread/pthread in Windows and what is more flexible and more simpler: low-level functions or classes.

推荐答案

每个进程都以单个线程开始。那么什么都没有办法在线程外执行任何代码。你总是至少有一个线程。在多线程引入之前的时代,整个程序运行在单个线程中,有时称为默认线程或主线程。



至于Windows功能:谷歌是你的朋友!在Windows API中查找它们很容易。



使用类库或低级函数的问题:在大多数实际情况中,您将使用类库,例如boost。这可以防止您犯下常见错误(很容易在这么复杂的主题中犯错)。您很少需要求助于低级函数,因为您想要做类库无法做到的事情。在这种情况下,您放弃了代码的轻松移植性,这在使用良好的类库时是一个很好的优势。
Every process starts with a single thread. So what there is no way to execute any code outside a thread. You always have at least one thread. And in the times before multi-thread was introduced, the entire program ran in that single thread, which is sometimes called the default thread or the main thread.

As for the Windows functions: Google is your friend! It's easy to look them up in the Windows API.

The question of using a class library or low-level function: In most practical cases you will be using a class library, for instance boost. This prevents you from making common mistakes (which are easily to be made in such a complicated subjects). Very rarely do you need to resort to the low-level functions, because you want to do somethings the class library is not able to do. In such cases you however give up the easy portability of your code, which is a great plus when using a good class library.


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

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