Critical Section in Satoshi client

1

Can you please point me to a tutorial for an explanation of the specific "Critical section" implementation that is used in main.cpp. I would like to understand a bit better how does it work. I studied concurrency before so I have some background to be able to understand it.

user1769523

Posted 2014-08-24T16:40:46.910

Reputation: 11

Answers

1

Are you talking about the CCriticalSection class? As you can see in sync.h, it's just a wrapper around Boost's recursive_mutex class. (It looks like the CCriticalSection name comes from Windows.)

You can read all about Boost's threading API in its documentation.

Nate Eldredge

Posted 2014-08-24T16:40:46.910

Reputation: 21 420

It is more clear now. But is CCriticalSection class related to CRITICAL_BLOCK? Also, what does the cs mean in cs_mapKeys?user1769523 2014-08-24T22:00:37.277

@user1759523: I don't know what CRITICAL_BLOCK is and I see no reference to it in the Bitcoin source. cs is just part of the name of the variable ´cs_mapKeys´ but I assume it is supposed to remind you that it is an object of type CCriticalSection.Nate Eldredge 2014-08-24T22:05:25.077

Maybe it was only in previous versions. See: https://github.com/bitcoin/bitcoin/blob/4405b78d6059e536c36974088a8ed4d9f0f29898/main.cpp

user1769523 2014-08-24T22:41:07.680

@user1759523: It looks like this has been replaced by LOCK. But anyway, you can see the code in sync.h; I'm not sure what you want to know specifically. These might be better questions for Stack Overflow since they are more about C++ in general than Bitcoin in particular.Nate Eldredge 2014-08-24T23:53:59.813