Giter VIP home page Giter VIP logo

Comments (4)

hsutter avatar hsutter commented on July 24, 2024

Editors call: Thanks! We agree this would be clearer with a destruction of im.

from cppcoreguidelines.

eyalroz avatar eyalroz commented on July 24, 2024

@hsutter :

We agree this would be clearer with a destruction of im.

Something like this perhaps?

{
  std::shared_ptr<const Image> im { read_image(somewhere) };

  std::thread t0 {shade, args0, top_left, image};
  std::thread t1 {shade, args1, top_right, image};
  std::thread t2 {shade, args2, bottom_left, image};
  std::thread t3 {shade, args3, bottom_right, image};

  // detach threads
}
// main thread no longer shares ownership
// last thread among t0-t3 to finish deletes the image

or maybe even

{
  std::shared_ptr<const Image> image { read_image(somewhere) };

  std::thread{shade, args0, top_left, image}.detach();
  std::thread{shade, args1, top_right, image}.detach();
  std::thread{shade, args2, bottom_left, image}.detach();
  std::thread{shade, args3, bottom_right, image}.detach();
}
// main thread no longer shares ownership
// last thread among the four shader threads to finish deletes the image

?

from cppcoreguidelines.

hsutter avatar hsutter commented on July 24, 2024

Yes, that's pretty much the direction we had in mind 👍

from cppcoreguidelines.

eyalroz avatar eyalroz commented on July 24, 2024

@hsutter : So, this bug is not actually resolved. After the new commit, the code as written results in std::terminate being called - as there is now not even a placeholder for the threads getting detached. You're saying that "detaching thread requires care etc." - but the detaching is not said to occur.

This will confuse users (and doubly so if they mistakenly imagine that the destruction involves joining - which they might believe happens; under that mis-perception, the use-case would actually be better served by a plain scoped Image rather than the shared_ptr. It's better to be extra clear in distinguishing the intended use case from the very-typical false use case for smart pointers.

Bottom line: Please either actually detach (which isn't hard after all), or say the threads get detached, explicitly.

from cppcoreguidelines.

Related Issues (20)

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.