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);
        }
   ...
2

LOCK(cs_main) causes the thread to stop execution until a lock can be obtained on cs_main. cs_main is an object representing a type/class/scope of lock. Once the lock is obtained, it lasts until the end of the LOCK statement's scope. (The LOCK macro creates an object on the stack, the destruction of which releases the lock.)

cs_main is already locked in that place, and LOCK uses recursive locks, so your LOCK doesn't do anything.

  • 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 Jun 30 '15 at 21:53
  • 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 Jun 30 '15 at 23:33
  • Theymos: LOCK uses recursive locks, so locking twice should just be a no-op. – Pieter Wuille Jun 30 '15 at 23:34
  • @PieterWuille so does a lock pause all other tasks / threads? Or just database writes ? – pinhead Dec 15 '17 at 20:59
  • @pinhead It pauses the thread it was invoked from, until the requested lock can be grabbed. – Pieter Wuille Dec 15 '17 at 21:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.