C++ Logo

std-proposals

Advanced search

Re: [std-proposals] std::thread::detach() can segfault

From: Phil Bouchard <boost_at_[hidden]>
Date: Wed, 11 Dec 2024 16:30:45 -0500
You're right, it's supposed to throw an exception. So the problem is in the pthread library in the pthread_detach() call itself more specifically.

You see, under high concurrency I'm creating simple threads followed immediately by detach(). And very rarely that call crashes.

I'm really surprised it crashes given I assumed libpthread was the most tested library of all time.


Thanks anyways,

-- 
Logo
Phil Bouchardfacebook icon
Founder & CEO
T: (819) 328-4743
E: phil_at_[hidden] | www.fornux.com
320-345 de la Gauchetière Ouest | Montréal (Qc), H2Z 0A2 Canada
BannerLe message ci-dessus, ainsi que les documents l'accompagnant, sont destinés uniquement aux personnes identifiées et peuvent contenir des informations privilégiées, confidentielles ou ne pouvant être divulguées. Si vous avez reçu ce message par erreur, veuillez le détruire.
This communication (and/or the attachments) is intended for named recipients only and may contain privileged or confidential information which is not to be disclosed. If you received this communication by mistake please destroy all copies.

On Dec 11, 2024, at 4:21 PM, Andre Kostur <andre_at_[hidden]> wrote:


Could you give a more concrete example of what you’re referring to?  If the constructor of std::thread couldn’t start the thread, it’s supposed to throw an exception, no?  So what do you mean by “properly created”?

On Wed, Dec 11, 2024 at 1:14 PM Phil Bouchard via Std-Proposals <std-proposals_at_[hidden]> wrote:
Greetings,

Given the following I came to realise there's no way in C++ to check if a thread was properly created or not (right after the equivalent C call to pthread_create()).

So I would like to suggest adding such check in joinable() call to do so.

Because under high concurrency a call to C++'s detach() can understandibly segfault.


Thanks,

-- 
Logo
Phil Bouchardfacebook icon
Founder & CEO
T: (819) 328-4743
E: phil_at_[hidden] | www.fornux.com
320-345 de la Gauchetière Ouest | Montréal (Qc), H2Z 0A2 Canada
BannerLe message ci-dessus, ainsi que les documents l'accompagnant, sont destinés uniquement aux personnes identifiées et peuvent contenir des informations privilégiées, confidentielles ou ne pouvant être divulguées. Si vous avez reçu ce message par erreur, veuillez le détruire.
This communication (and/or the attachments) is intended for named recipients only and may contain privileged or confidential information which is not to be disclosed. If you received this communication by mistake please destroy all copies.
--
Std-Proposals mailing list
Std-Proposals_at_[hidden]
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2024-12-11 21:31:01