PR_CreateThread 编辑

Creates a new thread.

Syntax

#include <prthread.h>

/wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PRThread* PR_CreateThread(
   /wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PRThreadType type,
   void (*start)(void *arg),
   void *arg,
   /wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PRThreadPriority priority,
   /wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PRThreadScope scope,
   /wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PRThreadState state,
   /wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PRUint32 stackSize);

Parameters

PR_CreateThread has the following parameters:

type
Specifies that the thread is either a user thread (PR_USER_THREAD) or a system thread (PR_SYSTEM_THREAD).
start
A pointer to the thread's root function, which is called as the root of the new thread. Returning from this function is the only way to terminate a thread.
arg
A pointer to the root function's only parameter. NSPR does not assess the type or the validity of the value passed in this parameter.
priority
The initial priority of the newly created thread.
scope
Specifies your preference for making the thread local (PR_LOCAL_THREAD), global (PR_GLOBAL_THREAD) or global bound (PR_GLOBAL_BOUND_THREAD). However, NSPR may override this preference if necessary.
state
Specifies whether the thread is joinable (PR_JOINABLE_THREAD) or unjoinable (PR_UNJOINABLE_THREAD).
stackSize
Specifies your preference for the size of the stack, in bytes, associated with the newly created thread. If you pass zero in this parameter, PR_CreateThread chooses the most favorable machine-specific stack size.

Returns

The function returns one of the following values:

  • If successful, a pointer to the new thread. This pointer remains valid until the thread returns from its root function.
  • If unsuccessful, (for example, if system resources are unavailable), NULL.

Description

If you want the thread to start up waiting for the creator to do something, enter a lock before creating the thread and then have the thread's root function enter and exit the same lock. When you are ready for the thread to run, exit the lock. For more information on locks and thread synchronization, see Introduction to NSPR.

If you want to detect the completion of the created thread, make it joinable. You can then use /wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PR_JoinThread to synchronize the termination of another thread.

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

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

发布评论

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

词条统计

浏览:26 次

字数:3833

最后编辑:8 年前

编辑次数:0 次

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