Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #89426

Re: Found a use case for `const` by value return, a shared queue

From Muttley@dastardlyhq.com
Newsgroups comp.lang.c++
Subject Re: Found a use case for `const` by value return, a shared queue
Date 2023-03-04 16:21 +0000
Organization A noiseless patient Spider
Message-ID <ttvr72$10ttg$1@dont-email.me> (permalink)
References (1 earlier) <tttfgj$n1eb$1@dont-email.me> <ttv4fi$unpg$1@dont-email.me> <ttvl2a$10a6v$1@dont-email.me> <ttvo23$10jbo$1@dont-email.me> <ttvqr8$10r76$1@dont-email.me>

Show all headers | View raw


On Sat, 4 Mar 2023 17:17:02 +0100
Bonita Montero <Bonita.Montero@gmail.com> wrote:
>Am 04.03.2023 um 16:28 schrieb Muttley@dastardlyhq.com:
>
>> mutex mt;
>> condition_variable cv;
>> 
>> void func(int id)
>> {
>>          unique_lock<mutex> ul(mt);
>>          cout << "Thread " << id << " waiting.\n";
>>          cv.wait(ul);
>>          cout << "Thread " << id << " started.\n";
>> }
>> 
>> 
>> int main()
>> {
>>          deque<thread> dq;
>>          for(int i=0;i < 10;++i) dq.push_back(thread(func,i));
>> 
>>          sleep(1);
>>          cv.notify_all();
>>          for(auto &thr: dq) thr.join();
>>          return 0;
>> }
>
>* This isn't a reusable component.

Why not? You can take the core bits out and put them anywhere.

>* Why are you using a deque for the threads and not for the items
>   you enqueue themselfes ? For the threads a vector<> would be more

You wanted a queue, you got a queue.

>   convenient to use and if you have a reserve() on it before creating
>   the threads this would be slightly more efficient.

Wow, really? Thanks for the heads up there.

>* You're using a wait which can't handle spurious wakeups.

Its a simple example.

>* sleep() doesn't make sense here and it isn't C++; you should use

It does make sense, it's a standard unix API call and I don't need to use
sleep_for.

>* You could use jthreads and strip the .join()s.

"Oh look at me, I can quote obscure parts of C++20 to try and look clever!"

>That's not professional programming.

Its perfectly fine as example code and far more intelligable that your 
overcomplicated load of show off bollocks.

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Found a use case for `const` by value return, a shared queue "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2023-02-04 22:32 +0100
  Re: Found a use case for `const` by value return, a shared queue "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2023-02-05 15:37 +0100
    Re: Found a use case for `const` by value return, a shared queue "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2023-02-05 22:45 +0100
  Re: Found a use case for `const` by value return, a shared queue "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-02-05 12:49 -0800
    Re: Found a use case for `const` by value return, a shared queue "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2023-02-05 22:39 +0100
      Re: Found a use case for `const` by value return, a shared queue "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2023-02-06 22:09 +0100
        Re: Found a use case for `const` by value return, a shared queue scott@slp53.sl.home (Scott Lurndal) - 2023-02-06 21:35 +0000
          Re: Found a use case for `const` by value return, a shared queue "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2023-02-06 23:44 +0100
            Re: Found a use case for `const` by value return, a shared queue scott@slp53.sl.home (Scott Lurndal) - 2023-02-07 01:34 +0000
            Re: Found a use case for `const` by value return, a shared queue Tim Rentsch <tr.17687@z991.linuxsc.com> - 2023-02-07 07:42 -0800
              Re: Found a use case for `const` by value return, a shared queue "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2023-02-07 17:34 +0100
                Re: Found a use case for `const` by value return, a shared queue Tim Rentsch <tr.17687@z991.linuxsc.com> - 2023-02-24 07:51 -0800
                Re: Found a use case for `const` by value return, a shared queue "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2023-02-24 18:48 +0100
                Re: Found a use case for `const` by value return, a shared queue Daniel <danielaparker@gmail.com> - 2023-02-26 09:50 -0800
                Re: Found a use case for `const` by value return, a shared queue Tim Rentsch <tr.17687@z991.linuxsc.com> - 2023-03-05 08:38 -0800
                Re: Found a use case for `const` by value return, a shared queue Tim Rentsch <tr.17687@z991.linuxsc.com> - 2023-03-05 08:43 -0800
                Re: Found a use case for `const` by value return, a shared queue "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2023-03-06 15:51 +0100
              Re: Found a use case for `const` by value return, a shared queue scott@slp53.sl.home (Scott Lurndal) - 2023-02-07 16:35 +0000
                Re: Found a use case for `const` by value return, a shared queue Tim Rentsch <tr.17687@z991.linuxsc.com> - 2023-02-22 06:28 -0800
                Re: Found a use case for `const` by value return, a shared queue scott@slp53.sl.home (Scott Lurndal) - 2023-02-22 15:01 +0000
                Re: Found a use case for `const` by value return, a shared queue Tim Rentsch <tr.17687@z991.linuxsc.com> - 2023-02-24 08:34 -0800
          Re: Found a use case for `const` by value return, a shared queue Paavo Helde <eesnimi@osa.pri.ee> - 2023-02-07 01:02 +0200
            Re: Found a use case for `const` by value return, a shared queue scott@slp53.sl.home (Scott Lurndal) - 2023-02-07 01:27 +0000
              Re: Found a use case for `const` by value return, a shared queue Paavo Helde <eesnimi@osa.pri.ee> - 2023-02-07 08:55 +0200
                Re: Found a use case for `const` by value return, a shared queue "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-02-07 12:11 -0800
          Re: Found a use case for `const` by value return, a shared queue James Kuyper <jameskuyper@alumni.caltech.edu> - 2023-02-07 00:19 -0500
            Re: Found a use case for `const` by value return, a shared queue Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-02-06 21:41 -0800
            Re: Found a use case for `const` by value return, a shared queue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-02-08 16:49 +0000
              Re: Found a use case for `const` by value return, a shared queue red floyd <no.spam.here@its.invalid> - 2023-02-08 11:11 -0800
                Re: Found a use case for `const` by value return, a shared queue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-02-09 00:40 +0000
                Re: Found a use case for `const` by value return, a shared queue Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-02-08 17:15 -0800
                Re: Found a use case for `const` by value return, a shared queue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-02-09 03:07 +0000
                Re: Found a use case for `const` by value return, a shared queue "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2023-02-09 04:54 +0100
                Re: Found a use case for `const` by value return, a shared queue Öö Tiib <ootiib@hot.ee> - 2023-02-08 23:38 -0800
                Re: Found a use case for `const` by value return, a shared queue David Brown <david.brown@hesbynett.no> - 2023-02-09 09:10 +0100
  Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-03 19:51 +0100
    Re: Found a use case for `const` by value return, a shared queue "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-03-03 12:45 -0800
      Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-04 05:38 +0100
        Re: Found a use case for `const` by value return, a shared queue "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-03-04 15:25 -0800
          Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-05 05:19 +0100
            Re: Found a use case for `const` by value return, a shared queue "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-03-05 13:41 -0800
              Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-06 16:11 +0100
    Re: Found a use case for `const` by value return, a shared queue Muttley@dastardlyhq.com - 2023-03-04 09:53 +0000
      Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-04 15:38 +0100
        Re: Found a use case for `const` by value return, a shared queue Muttley@dastardlyhq.com - 2023-03-04 15:28 +0000
          Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-04 17:17 +0100
            Re: Found a use case for `const` by value return, a shared queue Muttley@dastardlyhq.com - 2023-03-04 16:21 +0000
              Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-04 17:39 +0100
                Re: Found a use case for `const` by value return, a shared queue Muttley@dastardlyhq.com - 2023-03-04 16:57 +0000
                Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-04 18:06 +0100
                Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-04 18:10 +0100
                Re: Found a use case for `const` by value return, a shared queue Muttley@dastardlyhq.com - 2023-03-04 17:14 +0000
                Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-04 18:41 +0100
                Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-04 20:07 +0100
                Re: Found a use case for `const` by value return, a shared queue "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-03-04 15:26 -0800
                Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-05 05:18 +0100
                Re: Found a use case for `const` by value return, a shared queue "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-03-05 13:37 -0800
                Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-06 05:52 +0100
                Re: Found a use case for `const` by value return, a shared queue "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-03-06 15:29 -0800
                Re: Found a use case for `const` by value return, a shared queue "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-03-06 15:42 -0800
                Re: Found a use case for `const` by value return, a shared queue Muttley@dastardlyhq.com - 2023-03-06 09:18 +0000
                Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-06 11:18 +0100
                Re: Found a use case for `const` by value return, a shared queue Muttley@dastardlyhq.com - 2023-03-06 10:26 +0000
                Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-06 16:10 +0100
                Re: Found a use case for `const` by value return, a shared queue Muttley@dastardlyhq.com - 2023-03-06 17:07 +0000
                Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-07 06:44 +0100
                Re: Found a use case for `const` by value return, a shared queue Muttley@dastardlyhq.com - 2023-03-07 09:31 +0000
                Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-07 14:45 +0100
                Re: Found a use case for `const` by value return, a shared queue Muttley@dastardlyhq.com - 2023-03-07 15:59 +0000
                Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-07 17:37 +0100

csiph-web