Git Product home page Git Product logo

Comments (4)

SampsonCrowley avatar SampsonCrowley commented on May 27, 2024 1

The readme attempts to explain the reasoning ("unsynchronized mutation of state"). Instance variables in class methods aren't inherently un-safe.

The README touches briefly on the fact that mutating state without synchronizing it is unsafe, which should be obvious to anyone who understands threading, but the cops flag using them at all, which isn't explained to outsiders how something that is set-and-forget, read-only can be a threading danger. I'm not saying it's a bad thing to get people thinking about what they're doing more closely, but for people who don't know enough about threading practices, there could be more done to guide them on what they're doing wrong when they see an error pop up, IMO. If all they're using is boot time variables and never mutating the values, they would still see this error and end up confused as to what danger they're in instead of having more information on what that specific cop is targeting. The weight of a full mutex shouldn't be really needed for something that's boot-value only (like you said, hopefully safe)

It's definitely a complex problem, so that's why I think the docs could use some expansion from someone who knows what the target is. Some brief explanations on why thread.new is a default rule, instead of an optional add-on, etc

After getting some more details from you I think that's enough for me to put together a PR when I have time

from rubocop-thread_safety.

mikegee avatar mikegee commented on May 27, 2024

why is plain thread.new not safe, but thread.new with an injected value "safe"

That's a bug. They should be treated the same.

there are legitimate use cases for creating your own threads outside of your queuing system

Yup. I've created threads in my apps in couple different contexts where I need to disable this cop. Rake tasks and using threads to write specs for race conditions come to mind.

understand the reasoning behind items like "no ivar in class methods"

The readme attempts to explain the reasoning ("unsynchronized mutation of state"). Instance variables in class methods aren't inherently un-safe. The cop assumes the class is used in a multi-threaded application, where runtime mutations are un-safe.

I think you're pointing out the difference between run-time and boot-time mutation. That is a fundamental shortcoming of this project and static analysis of Ruby in general. Applications almost always mutate global state at startup, which is hopefully safe. This project cannot differentiate between start time and run time. Please disable the cops when you know they are pointing out problems that can't lead to threading bugs.

maybe I'm wrong but I don't see what thread issues would exist for class instance variables that wouldn't also exist for class variables

Class variables trigger a cop in base RuboCop, so we didn't add one here. You're right about their safety.

from rubocop-thread_safety.

mikegee avatar mikegee commented on May 27, 2024

Thanks for engaging! Documentation is definitely a shortcoming of this project.

from rubocop-thread_safety.

SampsonCrowley avatar SampsonCrowley commented on May 27, 2024

We can close this now I think. No reason just to leave it open just while I try to find some extra time

from rubocop-thread_safety.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.