什么是用户线程?

发布于 2024-11-02 20:35:29 字数 130 浏览 2 评论 0原文

什么是用户线程?下面的解释说它们是由用户空间管理的...请解释一下如何?

线程有时在用户空间库中实现,因此称为用户线程。内核不知道它们,因此它们在用户空间中进行管理和调度。

What are user threads? Below explanation says they are managed by userspace... Please explain how?

Threads are sometimes implemented in userspace libraries, thus called user threads. The kernel is not aware of them, so they are managed and scheduled in userspace.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

寄意 2024-11-09 20:35:29

如今,每个现代服务器或桌面操作系统以及所有主要移动操作系统都有一个本机线程库,因此这个问题不再那么相关了。但基本上,在此之前,已经有一些库 - 最著名的是“绿色线程库” - 将协作多任务线程实现为用户库。 “协作多任务”部分是重要的部分:一般来说,这样的库仅当线程调用某种允许发生切换的方法(“睡眠”、“yield”等)时才从一个线程切换到另一个线程。库一般不能进行抢占式时间切片;这是必须在操作系统级别完成的事情。

Every modern server or desktop OS, and all major mobile OSs, have a native thread library these days, so this question is not very relevant anymore. But basically, before this was the case, there were libraries -- most famously, the "Green threads library" -- which implemented cooperatively-multitasking threads as a user library. That "cooperatively multitasking" part is the important part: in general, such a library switches from one thread to another only when the thread calls some method that allows a switch to happen ("sleep", "yield", etc.) A user library generally can't do preemptive time-slicing; that's something that has to be done at the OS level.

寒冷纷飞旳雪 2024-11-09 20:35:29

Symbian OS 有一个活动对象框架,允许在单线程中处理异步事件
http://en.wikipedia.org/wiki/Active_object_%28Symbian_OS%29

Windows 也有光纤:
http://msdn.microsoft.com/en -us/library/ms682661%28v=vs.85%29.aspx

Symbian OS has an Active Object framework that allows async event handling in a single thread
http://en.wikipedia.org/wiki/Active_object_%28Symbian_OS%29

Windows also has Fibres:
http://msdn.microsoft.com/en-us/library/ms682661%28v=vs.85%29.aspx

动听の歌 2024-11-09 20:35:29

内核线程(也称为轻量级进程)由系统处理。它们提供了几个有趣的好处,主要的一个是可以在两个不同的处理器上调度两个线程,希望这会减少进程的执行时间。

然而,线程经常被用作编程模型。一个典型的例子是多客户端网络服务器,它等待传入连接并同时与其连接的客户端交换数据。在这种情况下,程序员可能想要创建很多线程并在它们之间快速切换。系统线程不太适应这一点。内核线程的数量是有限的(只有很少的未读),并且任何基本操作(创建破坏切换锁定)都是昂贵的,因为它必须在内核空间中执行。

另一方面,用户线程可以使用用户库中的 set_jmp()long_jmp() 来实现。由于它们不涉及内核,因此应用程序可以非常有效地创建/销毁用户线程以及在用户线程之间切换。

正如 Ernest 所说,用户线程不再常见,但是存在一种可以利用这两个世界的混合解决方案。

http://en.wikipedia.org/wiki/Thread_(计算机科学)#N:M_.28Hybrid_threading.29

Kernel threads (also called lightweight process) are handeled by the system. They offer several interesting benefits, the main one being that two threads can be scheduled on two different processors in the hope that this will reduce the execution time of your process.

However threads are often used as a programming model. A typical example is a multi-client webserver that waits for incoming connexion and simultaneously exchange data with its connected clients. In this case the programmer may want to create a lot of threads and switch between them very quickly. System threads are not very adapted to this. The number of kernel threads is limited (to few undreads) and any basic operation (creation destruction switching locking) is costly since it must be executed in kernel space.

The user threads on the other hand, can be implemented using set_jmp() and long_jmp() inside a user library. Since they don't involve the kernel an application can create/destroy and switch between user threads very efficiently.

As Ernest said, user threads are not very common any more, however there exists a hybrid solution that can take advantages of the two worlds.

http://en.wikipedia.org/wiki/Thread_(computer_science)#N:M_.28Hybrid_threading.29

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文