Threads 编辑

NSPR provides an execution environment that promotes the use of lightweight threads. Each thread is an execution entity that is scheduled independently from other threads in the same process. This chapter describes the basic NSPR threading API.

A thread has a limited number of resources that it truly owns. These resources include a stack and the CPU registers (including PC). To an NSPR client, a thread is represented by a pointer to an opaque structure of type /wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PRThread. A thread is created by an explicit client request and remains a valid, independent execution entity until it returns from its root function or the process abnormally terminates. Threads are critical resources and therefore require some management. To synchronize the termination of a thread, you can join it with another thread (see /wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PR_JoinThread). Joining a thread provides definitive proof that the target thread has terminated and has finished with both the resources to which the thread has access and the resources of the thread itself.

For an overview of the NSPR threading model and sample code that illustrates its use, see Introduction to NSPR.

For API reference information related to thread synchronization, see /wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/Locks and Condition Variables.

Threading Types and Constants

Threading Functions

Most of the functions described here accept a pointer to the thread as an argument. NSPR does not check for the validity of the thread. It is the caller's responsibility to ensure that the thread is valid. The effects of these functions on invalid threads are undefined.

Creating, Joining, and Identifying Threads

Controlling Thread Priorities

For an overview of the way NSPR controls thread priorities, see Setting Thread Priorities.

You set a thread's NSPR priority when you create it with /wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PR_CreateThread. After a thread has been created, you can get and set its priority with these functions:

Controlling Per-Thread Private Data

You can use these functions to associate private data with each of the threads in a process:

Interrupting and Yielding

Setting Global Thread Concurrency

Getting a Thread's Scope

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:98 次

字数:9478

最后编辑:7年前

编辑次数:0 次

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