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

  • Home
  • SEARCH
  • 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 8094891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:56:25+00:00 2026-06-05T20:56:25+00:00

I need to value an if condition, but I need to be careful about

  • 0

I need to value an if condition, but I need to be careful about possible modification of a variable by other threads.

My solution is

array.each do |anything|
    if (mutex.synchronize do shared_var <= my_var end)
        next
    end
end

It seems to work. But what is exactly the if statement checking? And how about this other code?

array.each do |anything|
    mutex.synchronize do
        if shared_var <= my_var
            next
        end
    end
end

Are they equivalent? Does the inner next do its job even if it is included in a mutex? And why?

Just look at the structure, I showed only the part of the program relevant for my question.

  • 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-05T20:56:26+00:00Added an answer on June 5, 2026 at 8:56 pm

    But what is exactly the if statement checking?

    synchronize returns whatever the block passed to it returns, so the if statement is ultimately checking shared_var <= my_var.

    And how about this other code?

    I think it’s self-explanatory what the if statement here is checking, and it is the same as above.

    Are they equivalent?

    No.

    Does the inner next do its job even if it is included in a mutex?

    No, and this is why they are not equivalent. When next is called inside the block of the synchronize call, it is nexting in that block (not the foreach), which is equivalent to return here since there’s no “next”. When it’s outside that block, it’s nexting over the actual outer block (foreach) you expect.

    Thus, you likely want the first code block.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i need Enumarable value from below class but give error public static Enumerable LoadDataByName(string
I have a boolean(primitive) variable in my bean. I need its value to be
MSDN docs say that only value types need boxing, but this does not apply
When I try to put some condition value into ContentValues variable, there is inserting
I need this to return a boolean value if the following condition is met
one simple question. I need to sum a value, when a condition is verified,
I have a problem. I need a Javascript function which increase (increment) variable value
I want to access the value of thumbnail using Smarty but I need some
i have to value $mo=strtotime($input_array['MondayOpen']); $mc=strtotime($input_array['MondayClose']); now i need a if condition to display
I have this query but I need the second WHERE condition to be dependent

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.