Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #79858
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: std::thread does not follow RAII principles |
| Date | 2021-05-28 21:01 +1200 |
| Message-ID | <ihbpqmFt2e6U3@mid.individual.net> (permalink) |
| References | (14 earlier) <d9f55950-a420-4063-a4ca-86a1cc8a6803n@googlegroups.com> <ihb4kdFt2e6U1@mid.individual.net> <d106201a-aab3-4964-a415-5cc4dc7e482en@googlegroups.com> <ihbb58Ft2e6U2@mid.individual.net> <ef425420-6a00-456d-bcc2-87f6851eae8dn@googlegroups.com> |
On 28/05/2021 18:07, Öö Tiib wrote:
> On Friday, 28 May 2021 at 07:51:05 UTC+3, Ian Collins wrote:
>> On 28/05/2021 15:37, Öö Tiib wrote:
>>>
>>> Very interesting ... but magical solutions make me even more worried.
>>> Is there some kind of secret exception thrown or some kind of alternative
>>> stack unwinding used or what? If secret exception then does
>>> catch(...) { mopup(); throw; } work or has it to be full RAII? If alternative
>>> stack unwinding then what it costs and do noexcept(true) functions
>>> in call stack compile still into that rainbow table because of it?
>>
>> I believe (at lease on Solaris), the "magic" is the runtime using
>> pthread_cleanup_push/pthread_cleanup_pop to manage the destructor
>> calling, there's no need for exceptions. There's nothing to stop you
>> doing this by hand...
>>
>> There a a number of behaviours which fall between two standards and we
>> have to rely on the quality of the implementation, this just happens to
>> be one.
>
> My threads typically do some sequential work that can be time consuming
> and complex (or otherwise why thread?). So I am unsure how to unit or
> automatic test canceling it cheaply enough as magic goes in the
> supernatural realm.
>
> When I do by hand, set some atomic flag (that thread checks if it
> should stop) and then join then I can measure, can mock that flag
> checking function. It is lot easier?
That is certainly a very common paradigm, one which my current day job
application (being cross-platform) uses exclusively. It is also one
where C++ threads provide everything you need.
Cancellation is probably uncommon in current C++ applications (I had to
go back to some of my old C++98 code to find a use case!) but it does
have its usages and if needed, it is good to know that your C++ runtime
handles object destruction correctly.
--
Ian.
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: std::thread does not follow RAII principles MrSpook_ry@939_6htz773e0qeya.eu - 2021-05-27 08:18 +0000
Re: std::thread does not follow RAII principles Bonita Montero <Bonita.Montero@gmail.com> - 2021-05-27 11:02 +0200
Re: std::thread does not follow RAII principles MrSpook_b28s@jxgz6zklebr1.tv - 2021-05-27 10:24 +0000
Re: std::thread does not follow RAII principles Bonita Montero <Bonita.Montero@gmail.com> - 2021-05-27 12:33 +0200
Re: std::thread does not follow RAII principles Bonita Montero <Bonita.Montero@gmail.com> - 2021-05-27 12:40 +0200
Re: std::thread does not follow RAII principles Bonita Montero <Bonita.Montero@gmail.com> - 2021-05-27 12:55 +0200
Re: std::thread does not follow RAII principles MrSpook_d4c3Jb7l7@8dftupdzk09cop2.co.uk - 2021-05-27 11:05 +0000
Re: std::thread does not follow RAII principles Bonita Montero <Bonita.Montero@gmail.com> - 2021-05-27 13:14 +0200
Re: std::thread does not follow RAII principles Bonita Montero <Bonita.Montero@gmail.com> - 2021-05-27 13:18 +0200
Re: std::thread does not follow RAII principles MrSpook_b_x@ukpge.org - 2021-05-27 15:54 +0000
Re: std::thread does not follow RAII principles Bonita Montero <Bonita.Montero@gmail.com> - 2021-05-27 19:32 +0200
Re: std::thread does not follow RAII principles Chris Vine <chris@cvine--nospam--.freeserve.co.uk> - 2021-05-27 19:00 +0100
Re: std::thread does not follow RAII principles Öö Tiib <ootiib@hot.ee> - 2021-05-27 17:52 -0700
Re: std::thread does not follow RAII principles Bonita Montero <Bonita.Montero@gmail.com> - 2021-05-28 05:24 +0200
Re: std::thread does not follow RAII principles Bonita Montero <Bonita.Montero@gmail.com> - 2021-05-28 05:27 +0200
Re: std::thread does not follow RAII principles Ian Collins <ian-news@hotmail.com> - 2021-05-28 14:59 +1200
Re: std::thread does not follow RAII principles Öö Tiib <ootiib@hot.ee> - 2021-05-27 20:37 -0700
Re: std::thread does not follow RAII principles Ian Collins <ian-news@hotmail.com> - 2021-05-28 16:50 +1200
Re: std::thread does not follow RAII principles Bonita Montero <Bonita.Montero@gmail.com> - 2021-05-28 06:53 +0200
Re: std::thread does not follow RAII principles Öö Tiib <ootiib@hot.ee> - 2021-05-27 23:07 -0700
Re: std::thread does not follow RAII principles Bonita Montero <Bonita.Montero@gmail.com> - 2021-05-28 08:26 +0200
Re: std::thread does not follow RAII principles Ian Collins <ian-news@hotmail.com> - 2021-05-28 21:01 +1200
Re: std::thread does not follow RAII principles Bonita Montero <Bonita.Montero@gmail.com> - 2021-05-28 13:04 +0200
Re: std::thread does not follow RAII principles Branimir Maksimovic <branimir.maksimovic@gmail.com> - 2021-05-28 17:06 +0000
Re: std::thread does not follow RAII principles scott@slp53.sl.home (Scott Lurndal) - 2021-05-28 17:51 +0000
Re: std::thread does not follow RAII principles Bonita Montero <Bonita.Montero@gmail.com> - 2021-05-28 20:00 +0200
Re: std::thread does not follow RAII principles Branimir Maksimovic <branimir.maksimovic@gmail.com> - 2021-05-28 21:42 +0000
Re: std::thread does not follow RAII principles Branimir Maksimovic <branimir.maksimovic@gmail.com> - 2021-05-28 17:03 +0000
Re: std::thread does not follow RAII principles Bonita Montero <Bonita.Montero@gmail.com> - 2021-05-28 03:55 +0200
Re: std::thread does not follow RAII principles Chris Vine <chris@cvine--nospam--.freeserve.co.uk> - 2021-05-28 12:02 +0100
Re: std::thread does not follow RAII principles Bonita Montero <Bonita.Montero@gmail.com> - 2021-05-28 13:15 +0200
Re: std::thread does not follow RAII principles Chris Vine <chris@cvine--nospam--.freeserve.co.uk> - 2021-05-28 12:40 +0100
Re: std::thread does not follow RAII principles Bonita Montero <Bonita.Montero@gmail.com> - 2021-05-28 13:55 +0200
Re: std::thread does not follow RAII principles Bonita Montero <Bonita.Montero@gmail.com> - 2021-05-28 13:57 +0200
Re: std::thread does not follow RAII principles Chris Vine <chris@cvine--nospam--.freeserve.co.uk> - 2021-05-28 14:29 +0100
Re: std::thread does not follow RAII principles Bonita Montero <Bonita.Montero@gmail.com> - 2021-05-28 15:48 +0200
Re: std::thread does not follow RAII principles Bonita Montero <Bonita.Montero@gmail.com> - 2021-05-28 16:16 +0200
Re: std::thread does not follow RAII principles Chris Vine <chris@cvine--nospam--.freeserve.co.uk> - 2021-05-28 15:45 +0100
Re: std::thread does not follow RAII principles Bonita Montero <Bonita.Montero@gmail.com> - 2021-05-28 17:30 +0200
Re: std::thread does not follow RAII principles Chris Vine <chris@cvine--nospam--.freeserve.co.uk> - 2021-05-28 19:54 +0100
Re: std::thread does not follow RAII principles Chris Vine <chris@cvine--nospam--.freeserve.co.uk> - 2021-05-28 15:08 +0100
Re: std::thread does not follow RAII principles Branimir Maksimovic <branimir.maksimovic@gmail.com> - 2021-05-28 17:08 +0000
Re: std::thread does not follow RAII principles Öö Tiib <ootiib@hot.ee> - 2021-05-29 01:42 -0700
Re: std::thread does not follow RAII principles Chris Vine <chris@cvine--nospam--.freeserve.co.uk> - 2021-05-29 13:05 +0100
Re: std::thread does not follow RAII principles Chris Vine <chris@cvine--nospam--.freeserve.co.uk> - 2021-05-29 13:44 +0100
Re: std::thread does not follow RAII principles Öö Tiib <ootiib@hot.ee> - 2021-05-29 06:34 -0700
Re: std::thread does not follow RAII principles Chris Vine <chris@cvine--nospam--.freeserve.co.uk> - 2021-05-29 14:48 +0100
Re: std::thread does not follow RAII principles Öö Tiib <ootiib@hot.ee> - 2021-05-29 07:59 -0700
Re: std::thread does not follow RAII principles Chris Vine <chris@cvine--nospam--.freeserve.co.uk> - 2021-05-29 18:15 +0100
Re: std::thread does not follow RAII principles Öö Tiib <ootiib@hot.ee> - 2021-05-29 19:03 -0700
Re: std::thread does not follow RAII principles Chris Vine <chris@cvine--nospam--.freeserve.co.uk> - 2021-05-30 11:48 +0100
Re: std::thread does not follow RAII principles Öö Tiib <ootiib@hot.ee> - 2021-05-30 09:35 -0700
Re: std::thread does not follow RAII principles Öö Tiib <ootiib@hot.ee> - 2021-05-29 06:51 -0700
Re: std::thread does not follow RAII principles MrSpook_jx@zp238i0_j1.net - 2021-05-28 11:11 +0000
csiph-web