2
Does LOCK(cs_main) pause and branach the program in order to do some necessary job before going on?
I'm trying to publish blocks reactively (as a selfish miner) upon receipt of inventory message from pfrom and react to it after *pfrom* catches up with the height of my secret block.
Following lines didn't help/there was no reaction on selfish node's side:
added following lines in main.cpp: after l. 3662
...
{
LOCK(cs_main);
pfrom->PushMessage("inv", pfrom->vPrivateInv);
}
...
Ok thanks. How do I release lock after completion of following task? Is lock(cs_main) the correct lock to use at this place – Aliakbar Ahmadi – 2015-06-30T21:53:11.247
It's automatically released at the end of the scope in which the LOCK is declared. It works similar to a boost::lock, but has some extra debugging logic that can be enabled. – Pieter Wuille – 2015-06-30T23:33:31.317
Theymos: LOCK uses recursive locks, so locking twice should just be a no-op. – Pieter Wuille – 2015-06-30T23:34:20.493
@PieterWuille so does a lock pause all other tasks / threads? Or just database writes ? – pinhead – 2017-12-15T20:59:08.810
@pinhead It pauses the thread it was invoked from, until the requested lock can be grabbed. – Pieter Wuille – 2017-12-15T21:03:17.157
@PieterWuille but what is locked? – pinhead – 2017-12-15T21:04:04.670
@pinhead I don't know what that means. There are a number of locks (cs_main being one of them), and each lock can be held by at most one thread at a time. If the lock is already held by another thread, LOCK(cs_main) will pause until the lock becomes available. In any case, the code being executed will not progress past the LOCK(cs_main) statement without holding the cs_main lock. – Pieter Wuille – 2017-12-15T21:06:15.867
@PieterWuille thanks that answers my question – pinhead – 2017-12-15T21:10:16.023