tags:

views:

87

answers:

2

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? Thanks.

+1  A: 

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

Jamie Keeling
+1  A: 

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.

Mike Webb