PR_NewThreadPrivateIndex 编辑

Returns a new index for a per-thread private data table and optionally associates a destructor with the data that will be assigned to the index.

Syntax

#include <prthread.h>

PRStatus PR_NewThreadPrivateIndex(
   /wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PRUintn *newIndex,
   /wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PRThreadPrivateDTOR destructor);

Parameters

PR_NewThreadPrivateIndex has the following parameters:

newIndex
On output, an index that is valid for all threads in the process. You use this index with /wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PR_SetThreadPrivate and /wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PR_GetThreadPrivate.
destructor
Specifies a destructor function /wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PRThreadPrivateDTOR for the private data associated with the index. This function can be specified as NULL.

Returns

The function returns one of the following values:

  • If successful, PR_SUCCESS.
  • If the total number of indices exceeds 128, PR_FAILURE.

Description

If PR_NewThreadPrivateIndex is successful, every thread in the same process is capable of associating private data with the new index. Until the data for an index is actually set, the value of the private data at that index is NULL. You pass this index to /wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PR_SetThreadPrivate and /wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PR_GetThreadPrivate to set and retrieve data associated with the index.

When you allocate the index, you may also register a destructor function of type /wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PRThreadPrivateDTOR. If a destructor function is registered with a new index, it will be called at one of two times, as long as the private data is not NULL:

The index maintains independent data values for each binding thread. A thread can get access only to its own thread-specific data. There is no way to deallocate a private data index once it is allocated.

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

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

发布评论

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

词条统计

浏览:86 次

字数:3551

最后编辑:7年前

编辑次数:0 次

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