Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #85926
| From | "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: Move constructor in lock_guard safe? |
| Date | 2022-08-14 16:22 -0700 |
| Organization | A noiseless patient Spider |
| Message-ID | <tdc032$3adh4$1@dont-email.me> (permalink) |
| References | <tdaghg$jkn$1@news.nntp4.net> <tdao7b$34vec$1@dont-email.me> <tdbgou$386bu$1@dont-email.me> <tdbrpc$bts$1@news.nntp4.net> |
On 8/14/2022 3:08 PM, Marcel Mueller wrote:
> Am 14.08.22 um 21:00 schrieb Chris M. Thomasson:
>> Launching a thread in a ctor of object A can and will start operating
>> on the state of object A before the ctor of A is finished...
>
> The thread is kicked explicitly in the last line of the ctor after
> several other initializations and the class is internal and has no sub
> classes. It could safely start before the ctor really returned.
Well, starting threads in the ctor is still a bit scary too me... ;^) I
have seen shit like:
// quick and dirty pseudo-code
struct foo
{
int a;
foo()
{
// launch a thread using foo_thread(this);
a = 42;
}
static void foo_thread(foo* self)
{
int sa = self->a;
assert(sa == 42);
}
}
foo::foo_thread can start up and read foo::a before the ctor was
finished. I was asked why can some foo threads not see foo::a as 42? Yikes!
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Move constructor in lock_guard safe? Marcel Mueller <news.5.maazl@spamgourmet.org> - 2022-08-14 11:50 +0200
Re: Move constructor in lock_guard safe? Paavo Helde <eesnimi@osa.pri.ee> - 2022-08-14 15:01 +0300
Re: Move constructor in lock_guard safe? Öö Tiib <ootiib@hot.ee> - 2022-08-14 06:01 -0700
Re: Move constructor in lock_guard safe? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2022-08-14 12:00 -0700
Re: Move constructor in lock_guard safe? Marcel Mueller <news.5.maazl@spamgourmet.org> - 2022-08-15 00:08 +0200
Re: Move constructor in lock_guard safe? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2022-08-14 16:22 -0700
Re: Move constructor in lock_guard safe? Paavo Helde <eesnimi@osa.pri.ee> - 2022-08-15 09:38 +0300
Re: Move constructor in lock_guard safe? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2022-08-14 23:56 -0700
Re: Move constructor in lock_guard safe? scott@slp53.sl.home (Scott Lurndal) - 2022-08-15 15:31 +0000
Re: Move constructor in lock_guard safe? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2022-08-15 11:11 -0700
csiph-web