代码来自 TBB 书

发布于 2024-08-30 06:45:34 字数 315 浏览 4 评论 0原文

我正在读一本书:英特尔线程构建模块。我常常很难理解它们。例如,以下代码来自本书(第112页):

Node* AllocateNode() {
Node* n;
FreeListMutexType::scoped_lock lock;
lock.acquire(FreeListMutex);
n=FreeList;
if(n)
Freelist=n->next;
lock.release();
if(!n)
n=new Node();

return n;
}

关于此代码还有其他介绍。我无法理解。这意味着什么?怎样才能更好地理解这本书呢?

I am reading the book: Intel Threading Building Blocks. I often have difficulties understanding them. For example,the following code is from the book(page 112):

Node* AllocateNode() {
Node* n;
FreeListMutexType::scoped_lock lock;
lock.acquire(FreeListMutex);
n=FreeList;
if(n)
Freelist=n->next;
lock.release();
if(!n)
n=new Node();

return n;
}

There is other introduction regarding this code. I can not understand it. What does it means? How can I understand this book better?

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

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

发布评论

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

评论(2

音盲 2024-09-06 06:45:34

理解代码中发生的事情的关键是理解每个部分。确保您了解互斥锁、线程和竞争条件的概念。还要确保您知道 FreeListMutex 和 FreeList 对象是什么以及它们的用途。您可能需要去谷歌并做一些研究,但是如果您理解这些片段,您可以查看代码的每个部分并弄清楚它在做什么。

The key to understanding what is going on in the code is understanding each part. Make sure you understand the concepts for mutex locks, threading, and race conditions. Also make sure you know what the objects FreeListMutex and FreeList are and what they do. You may have to go to Google and do some research, but if you understand the pieces you can look through each part of the code and figure out what it's doing.

原来是傀儡 2024-09-06 06:45:34

这本书肯定详细说明了它的作用吗?似乎是一种使用互斥体提供安全访问的方法

Surely the book details what it does? Seems like a method of providing safe access using mutex's

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