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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:05:59+00:00 2026-06-03T07:05:59+00:00

I am working on a multi-threading program in Ruby, just want to make sure

  • 0

I am working on a multi-threading program in Ruby, just want to make sure a simple question.

For example I have a class called School, and two other classes are Boy and Girl.

In School I have a hash that keeps track all boys and girls attendance. And I make each boy/girl a thread in School (so that they can have activity individually)

I want all boys and girls threads can see and make change to the attendance hash. (like if a girl comes to school, check her name in the hash, when she leaves, delete her name in the hash)

I know I can use monitor to do a thread lock, but I dont familiar with scripting language so I am not sure how all threads can see the hash variable and modify them. (kind of like static in C/JAVA)

Thank you

  • 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-03T07:06:01+00:00Added an answer on June 3, 2026 at 7:06 am

    Something like this :

    threads = []
    hash = {g:0,n:0}
    m = Mutex.new
    
    threads << Thread.new(optional_pass_by_value) do |value|
      #do whatever
      #modify hash
      m.synchronize {hash[:g] += 1} #By using synchronize you get an atomic behavior
      #Only one thread will be able to access and modify this hash at one time.
    end
    
    threads.each {|t| t.join}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made a multi-threading program. In it, the main thread starts 10 threads
I'm working on a free, simple, hopefully multi-platform hotkey launcher tool, written in Ruby.
So, I'm trying to make a simple multi-threaded program that validates the Collatz Conjecture
I’m working on a multi dimensions array but i have a problem Imagine I
I'm using net beans for Java development. I'm working on a multi threading application
I am working on multi-threading using the following codes in XCode4: #import <Foundation/Foundation.h> bool
after reading a few articles, I am still not sure I understand Multi-threading to
I've got a problem with multi-threading - I am working on a framework which
I am working on a little multi-threading project.The system could be divided into 2
I have recently heard about the Web Workers spec that defines API for multi-threading

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.