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 7536229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:31:04+00:00 2026-05-30T06:31:04+00:00

Does run block executed as a whole in EM (without a context switch)? And

  • 0

Does "run" block executed as a whole in EM (without a context switch)? And in this example, will be there a race condition in the if clause?

EventMachine.run {
  @current_value = 0
  EventMachine::WebSocket.start(:host => "0.0.0.0", :port => 8080, :debug => true) do |ws|
    ws.onopen {
      @current_value += 1
      if @current_value >= 4 # Race condition?
        # Code Block
        @current_value = 0
      end

      ws.onmessage { |msg|
        # puts msg
      }

      ws.onclose {
        # puts "disconnected"
      }
    }  
  end
end
  • 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-05-30T06:31:06+00:00Added an answer on May 30, 2026 at 6:31 am

    EventMachine, by default, is single threaded, so there really shouldn’t be any race conditions unless you’re introducing threads.

    An event-loop model means you perform small, simple actions in rapid sequence instead of long, blocking methods that require their own threads. As such you should never have two pieces of code executing in parallel.

    It is your responsibility to yield control to the event-loop frequently at points you define.

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

Sidebar

Related Questions

Possible Duplicate: Does a finally block always run? I learned that the finally clause
Does it run in a loop polling the contents? (Highly unlikely and inefficient.) Or
Code below does not run correctly and throws InvalidOperationExcepiton . public void Foo() {
The following code does not run as rootNode is null when retrieved by name
Does Drupal parse (and/or run) hooks that are unrelated to the content being loaded
Does the DLR or even better Iron Python run in Silverlight?
Does anyone know how I'd run plain text passwords through the authlogic hasing algorithm
Does anyone know of a similar product to Citrix Server that'll run on the
Does anybody have a short code sample that can be run in the VS
Does anybody know what's going on here: I run hibernate 3.2.6 against a PostgreSQL

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.