Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8237755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:34:27+00:00 2026-06-07T19:34:27+00:00

I once saw a snip of code as below, /** Starts a synchronized block

  • 0

I once saw a snip of code as below,

/** Starts a synchronized block
*
*   This macro starts a block synchronized on its argument x
*   Note that the synchronized block defines a scope (i.e. { })
*   All variables declared in it will live inside this block only
*/
#define SYNCHRONIZE_ON(x) { \
                const abcd::LockBase & __lock = \
                                abcd::MakeLock(x); __lock;

/** Ends a synchronized block */
#define END_SYNCHRONIZE   }

The SYNCHRONIZE_ON and END_SYNCHRONIZE are used together to synchronize on an object.
The macro SYNCHRONIZE_ON defines a variable ____lock in it’s block.

The question here is: what is the sentence __lock; (after the abcd::MakeLock(x);) for? Notice that this sentence consist of only the variable name.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T19:34:30+00:00Added an answer on June 7, 2026 at 7:34 pm

    Image you have this code:

    SYNCHRONIZE_ON(myVariable)
       // Do stuff
    END_SYNCHRONIZE
    

    It’ll be rewritten to:

    {
        abcd::LockBase& __lock = abcd::MakeLock(myVariable);
        __lock;
    
        // Do stuff
    }
    

    Actually the __lock variable won’t be used in your code, it’s there only to dispose the critical section (if it’s what it uses) when it’ll go out of scope.

    The problem with that code is that it’ll generate tons of warning because __lock is declared but never used. That statement is there to prevent those warnings and it’ll be optimized away by the compiler (because it has no side effects), this is what your compiler will actually perform:

    {
        abcd::LockBase& __lock = abcd::MakeLock(myVariable);
    
        // Do stuff
    }
    

    EDIT
    This code should suppress “unused variable” warning but it may not save from “expression has no effect” warning. pragmas to disable specific warning aren’t portable at all and Internet is full of workarounds to avoid them, like this (it seems to be pretty portable across compilers).

    {
        abcd::LockBase& __lock = abcd::MakeLock(myVariable);
        (void)__lock;
    
        // Do stuff
    }
    

    In this case a better solution may be to split declaration and lock acquisition, like this:

    {
        abcd::LockBase& __lock = abcd::MakeLock(myVariable);
        __lock.Acquire();
    
        // Do stuff
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I once saw this nice little snippet of code below, here at SO: template<typename
Actually i once saw some PHP code on php.net but i forgot its name
I once used a code snippet I saw/found in the past that would turn
I once saw a framework or code from some PHP that had an error
there was this plugin i once saw and i cant find it anymore. its
I once saw this line of code: std::cout %lt;%lt; Hello world! %lt;%lt; std:: endl;
I saw this demo once that printed out a paragraph of text (like you'd
I saw something once for wrappers used to do this but it asked for
Once, I saw an example like this: var a, x, y; var r =
I'm sure I saw this happening to me once. In a 64-bit OS with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.