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


Groups > comp.lang.c++ > #88973 > unrolled thread

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

Started by"Alf P. Steinbach" <alf.p.steinbach@gmail.com>
First post2023-02-04 22:32 +0100
Last post2023-03-07 17:37 +0100
Articles 20 on this page of 70 — 14 participants

Back to article view | Back to comp.lang.c++


Contents

  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

Page 3 of 4 — ← Prev page 1 2 [3] 4  Next page →


#89458

From"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>
Date2023-03-05 13:41 -0800
Message-ID<tu329r$1emi7$2@dont-email.me>
In reply to#89440
On 3/4/2023 8:19 PM, Bonita Montero wrote:
> Am 05.03.2023 um 00:25 schrieb Chris M. Thomasson:
> 
>> I have seen too many bugs in code that others have labeled
>> trivial  before... Btw, I am busy on another project. :^)
> 
> Idiot. You didn't have a look at my code.
> 

I did, but not long enough to verify it as 100% kosher.

[toc] | [prev] | [next] | [standalone]


#89480

FromBonita Montero <Bonita.Montero@gmail.com>
Date2023-03-06 16:11 +0100
Message-ID<tu4vnu$1nbtv$2@dont-email.me>
In reply to#89458
Am 05.03.2023 um 22:41 schrieb Chris M. Thomasson:

> I did, but not long enough to verify it as 100% kosher.

The parts that are tricky are purely declarative.
The code itself is trivial.

[toc] | [prev] | [next] | [standalone]


#89421

FromMuttley@dastardlyhq.com
Date2023-03-04 09:53 +0000
Message-ID<ttv4fi$unpg$1@dont-email.me>
In reply to#89412
On Fri, 3 Mar 2023 19:51:19 +0100
Bonita Montero <Bonita.Montero@gmail.com> wrote:
>Use this thread-queue:

No thanks.

Life's too short to figure out what its doing but a thread queue should be
a couple of lines of code.

[toc] | [prev] | [next] | [standalone]


#89422

FromBonita Montero <Bonita.Montero@gmail.com>
Date2023-03-04 15:38 +0100
Message-ID<ttvl2a$10a6v$1@dont-email.me>
In reply to#89421
Am 04.03.2023 um 10:53 schrieb Muttley@dastardlyhq.com:

> Life's too short to figure out what its doing but a thread queue should be
> a couple of lines of code.

Show me your code then I show your mistakes and your less to
convenient to use code. Except from the used concepts the code
is straitforward.

[toc] | [prev] | [next] | [standalone]


#89424

FromMuttley@dastardlyhq.com
Date2023-03-04 15:28 +0000
Message-ID<ttvo23$10jbo$1@dont-email.me>
In reply to#89422
On Sat, 4 Mar 2023 15:38:24 +0100
Bonita Montero <Bonita.Montero@gmail.com> wrote:
>Am 04.03.2023 um 10:53 schrieb Muttley@dastardlyhq.com:
>
>> Life's too short to figure out what its doing but a thread queue should be
>> a couple of lines of code.
>
>Show me your code then I show your mistakes and your less to
>convenient to use code. Except from the used concepts the code
>is straitforward.

#include <unistd.h>

#include <iostream>
#include <thread>
#include <mutex>
#include <deque>
#include <condition_variable>

using namespace std;

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;
}

[toc] | [prev] | [next] | [standalone]


#89425

FromBonita Montero <Bonita.Montero@gmail.com>
Date2023-03-04 17:17 +0100
Message-ID<ttvqr8$10r76$1@dont-email.me>
In reply to#89424
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 are you using a deque for the threads and not for the items
   you enqueue themselfes ? For the threads a vector<> would be more
   convenient to use and if you have a reserve() on it before creating
   the threads this would be slightly more efficient.
* You're using a wait which can't handle spurious wakeups.
* sleep() doesn't make sense here and it isn't C++; you should use
   this_thread::sleep_for() if you do it at all.
* You could use jthreads and strip the .join()s.

That's not professional programming.

[toc] | [prev] | [next] | [standalone]


#89426

FromMuttley@dastardlyhq.com
Date2023-03-04 16:21 +0000
Message-ID<ttvr72$10ttg$1@dont-email.me>
In reply to#89425
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.

[toc] | [prev] | [next] | [standalone]


#89427

FromBonita Montero <Bonita.Montero@gmail.com>
Date2023-03-04 17:39 +0100
Message-ID<ttvs4k$1102f$1@dont-email.me>
In reply to#89426
Am 04.03.2023 um 17:21 schrieb Muttley@dastardlyhq.com:

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

A reusable component is sth. like mine where you won't have to deal
with all the details.

>> * 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.

Yes, but a queue with data shared among the threads.
A queue of threads doesn't make sense.

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

> Its a simple example.

It doesn't work reliably because of what I said. You might have
spurious wakeups, i.e. wakeups which occur although nothong happened
on the sender side; that's documented C++-behaviour.

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

If you have a producer-consumer-pattern you don't sleep(), even not with
C++-means.

>> * 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!"

The language becomes increasingly more convenient to to use with newer
versions; jthread is one aspect of that.

>> That's not professional programming.

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

Idiot.

[toc] | [prev] | [next] | [standalone]


#89428

FromMuttley@dastardlyhq.com
Date2023-03-04 16:57 +0000
Message-ID<ttvta3$113ui$1@dont-email.me>
In reply to#89427
On Sat, 4 Mar 2023 17:39:05 +0100
Bonita Montero <Bonita.Montero@gmail.com> wrote:
>Am 04.03.2023 um 17:21 schrieb Muttley@dastardlyhq.com:
>
>> Why not? You can take the core bits out and put them anywhere.
>
>A reusable component is sth. like mine where you won't have to deal
>with all the details.

sth?

Understanding your overcomplicated code is a detail in itself.

>>> * 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.
>
>Yes, but a queue with data shared among the threads.
>A queue of threads doesn't make sense.

Well fair enough. In which case something like this. 

T consumer()
{
	mtx.lock();
	auto whatever = dq.pop_front();
	mtx.unlock();
	return whatever;
}

Similar code for popping it in to the q.

>>> * You're using a wait which can't handle spurious wakeups.
>
>> Its a simple example.
>
>It doesn't work reliably because of what I said. You might have
>spurious wakeups, i.e. wakeups which occur although nothong happened
>on the sender side; that's documented C++-behaviour.

So pass wait() a lambda that checks a flag so see if something did happen.

>> It does make sense, it's a standard unix API call and I don't need to use
>> sleep_for.
>
>If you have a producer-consumer-pattern you don't sleep(), even not with
>C++-means.

As I said you muppet, it was example code. The sleep is so you can see
what is going on. Also FYI sleep() only affects the thread its called from
so it simply pauses the main thread until all the threads are set up.

>>> * 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!"
>
>The language becomes increasingly more convenient to to use with newer
>versions; jthread is one aspect of that.

It avoids a single call to detach(). A valuable addition to the language. Not.

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

Truth hurt?

[toc] | [prev] | [next] | [standalone]


#89429

FromBonita Montero <Bonita.Montero@gmail.com>
Date2023-03-04 18:06 +0100
Message-ID<ttvtoi$114te$1@dont-email.me>
In reply to#89428
Am 04.03.2023 um 17:57 schrieb Muttley@dastardlyhq.com:
> On Sat, 4 Mar 2023 17:39:05 +0100

> Bonita Montero <Bonita.Montero@gmail.com> wrote:

>> A reusable component is sth. like mine where you won't have to deal
>> with all the details.

> Understanding your overcomplicated code is a detail in itself.

Understanding all what a unordered_map is also complicated.
But you only have to understand the the interface.

> Well fair enough. In which case something like this.
> 
> T consumer()
> {
> 	mtx.lock();
> 	auto whatever = dq.pop_front();
> 	mtx.unlock();
> 	return whatever;
> }

This also doesn't work because you don't test if there are items
inside the queue.


>> It doesn't work reliably because of what I said. You might have
>> spurious wakeups, i.e. wakeups which occur although nothong happened
>> on the sender side; that's documented C++-behaviour.

> So pass wait() a lambda that checks a flag so see if something did happen.

F.e..

>> If you have a producer-consumer-pattern you don't sleep(), even not with
>> C++-means.

> As I said you muppet, it was example code. ...

Even for example code you don't need a wait().

>> The language becomes increasingly more convenient to to use with newer
>> versions; jthread is one aspect of that.

> It avoids a single call to detach(). A valuable addition to the language. Not.

If you'd detach returning from main() and ending the program could occur
earlier than any threads would complete. There's no guarantee that your
runtime waits on detached threads.

[toc] | [prev] | [next] | [standalone]


#89430

FromBonita Montero <Bonita.Montero@gmail.com>
Date2023-03-04 18:10 +0100
Message-ID<ttvu03$1163d$1@dont-email.me>
In reply to#89429
Am 04.03.2023 um 18:06 schrieb Bonita Montero:

> If you'd detach returning from main() and ending the program could occur
> earlier than any threads would complete. There's no guarantee that your
> runtime waits on detached threads.

F.e. this prints nothing on my Windows- and Linux-PC:

#include <iostream>
#include <thread>

using namespace std;

int main()
{
	thread( []() { cout << "hello world" << endl; } ).detach();
}

[toc] | [prev] | [next] | [standalone]


#89431

FromMuttley@dastardlyhq.com
Date2023-03-04 17:14 +0000
Message-ID<ttvuah$11793$1@dont-email.me>
In reply to#89429
On Sat, 4 Mar 2023 18:06:47 +0100
Bonita Montero <Bonita.Montero@gmail.com> wrote:
>Am 04.03.2023 um 17:57 schrieb Muttley@dastardlyhq.com:
>> On Sat, 4 Mar 2023 17:39:05 +0100
>> T consumer()
>> {
>> 	mtx.lock();
>> 	auto whatever = dq.pop_front();
>> 	mtx.unlock();
>> 	return whatever;
>> }
>
>This also doesn't work because you don't test if there are items
>inside the queue.

Fine, do a check on the same line and make the return value an optional or
a pointer or a pair with a bool flag or 101 other ways of notifying the caller
when there's nothing available.

Either way, its still only a few lines of simple code unlike yours.

>>> It doesn't work reliably because of what I said. You might have
>>> spurious wakeups, i.e. wakeups which occur although nothong happened
>>> on the sender side; that's documented C++-behaviour.
>
>> So pass wait() a lambda that checks a flag so see if something did happen.
>
>F.e..

No idea what that means.

>>> If you have a producer-consumer-pattern you don't sleep(), even not with
>>> C++-means.
>
>> As I said you muppet, it was example code. ...
>
>Even for example code you don't need a wait().

Have you ever used condition variables?

>> It avoids a single call to detach(). A valuable addition to the language.
>Not.
>
>If you'd detach returning from main() and ending the program could occur
>earlier than any threads would complete. There's no guarantee that your
>runtime waits on detached threads.

There is that, but its hardly important. If you main thread exits then you
almost certainly don't care what any detached threads are doing at that point
anyway.

[toc] | [prev] | [next] | [standalone]


#89432

FromBonita Montero <Bonita.Montero@gmail.com>
Date2023-03-04 18:41 +0100
Message-ID<ttvvpa$11bgg$1@dont-email.me>
In reply to#89431
Am 04.03.2023 um 18:14 schrieb Muttley@dastardlyhq.com:

> On Sat, 4 Mar 2023 18:06:47 +0100

>> This also doesn't work because you don't test if there are items
>> inside the queue.

> Fine, do a check ....

You said that you would give an example.
But it doesn't work for a few reasons.

> Have you ever used condition variables?

Check my code, it uses a CV.

>> If you'd detach returning from main() and ending the program could occur
>> earlier than any threads would complete. There's no guarantee that your
>> runtime waits on detached threads.

> There is that, but its hardly important. ...

For your example code it would be.

[toc] | [prev] | [next] | [standalone]


#89433

FromBonita Montero <Bonita.Montero@gmail.com>
Date2023-03-04 20:07 +0100
Message-ID<tu04ri$11qlv$3@dont-email.me>
In reply to#89432
Am 04.03.2023 um 18:41 schrieb Bonita Montero:
> Am 04.03.2023 um 18:14 schrieb Muttley@dastardlyhq.com:
> 
>> On Sat, 4 Mar 2023 18:06:47 +0100
> 
>>> This also doesn't work because you don't test if there are items
>>> inside the queue.
> 
>> Fine, do a check ....
> 
> You said that you would give an example.
> But it doesn't work for a few reasons.
> 
>> Have you ever used condition variables?
> 
> Check my code, it uses a CV.
> 
>>> If you'd detach returning from main() and ending the program could occur
>>> earlier than any threads would complete. There's no guarantee that your
>>> runtime waits on detached threads.
> 
>> There is that, but its hardly important. ...
> 
> For your example code it would be.


My code looks like f.e. like this:

thread_queue<string> stringQueue;
...
stringQueue.enqueue( "hello world" );
...
string dequeued( stringQueue.dequeue() );

That's all.

[toc] | [prev] | [next] | [standalone]


#89438

From"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>
Date2023-03-04 15:26 -0800
Message-ID<tu0k33$13eme$2@dont-email.me>
In reply to#89433
On 3/4/2023 11:07 AM, Bonita Montero wrote:
> Am 04.03.2023 um 18:41 schrieb Bonita Montero:
>> Am 04.03.2023 um 18:14 schrieb Muttley@dastardlyhq.com:
>>
>>> On Sat, 4 Mar 2023 18:06:47 +0100
>>
>>>> This also doesn't work because you don't test if there are items
>>>> inside the queue.
>>
>>> Fine, do a check ....
>>
>> You said that you would give an example.
>> But it doesn't work for a few reasons.
>>
>>> Have you ever used condition variables?
>>
>> Check my code, it uses a CV.
>>
>>>> If you'd detach returning from main() and ending the program could 
>>>> occur
>>>> earlier than any threads would complete. There's no guarantee that your
>>>> runtime waits on detached threads.
>>
>>> There is that, but its hardly important. ...
>>
>> For your example code it would be.
> 
> 
> My code looks like f.e. like this:
> 
> thread_queue<string> stringQueue;
> ...
> stringQueue.enqueue( "hello world" );
> ...
> string dequeued( stringQueue.dequeue() );
> 
> That's all.
> 

Take the time to model it in a race detector.

[toc] | [prev] | [next] | [standalone]


#89439

FromBonita Montero <Bonita.Montero@gmail.com>
Date2023-03-05 05:18 +0100
Message-ID<tu154a$17p9j$1@dont-email.me>
In reply to#89438
Am 05.03.2023 um 00:26 schrieb Chris M. Thomasson:

> Take the time to model it in a race detector.

You are an idiot; no one needs a race-detector for such simple code.

[toc] | [prev] | [next] | [standalone]


#89457

From"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>
Date2023-03-05 13:37 -0800
Message-ID<tu3239$1emi7$1@dont-email.me>
In reply to#89439
On 3/4/2023 8:18 PM, Bonita Montero wrote:
> Am 05.03.2023 um 00:26 schrieb Chris M. Thomasson:
> 
>> Take the time to model it in a race detector.
> 
> You are an idiot; no one needs a race-detector for such simple code.

There is nothing wrong with using a race-detector. Model the simple code 
in the detector, then move it into your C++ code. There is nothing wrong 
with modeling a lock-based and/or lock-free, wait-free synchronization 
scheme in a race detector, before, you flesh it out in real code.

[toc] | [prev] | [next] | [standalone]


#89467

FromBonita Montero <Bonita.Montero@gmail.com>
Date2023-03-06 05:52 +0100
Message-ID<tu3rf7$1jpti$1@dont-email.me>
In reply to#89457
Am 05.03.2023 um 22:37 schrieb Chris M. Thomasson:

> There is nothing wrong with using a race-detector. ...
And there's noting wrong to buy a supercomputer to proof that
one plus one is two.

[toc] | [prev] | [next] | [standalone]


#89498

From"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>
Date2023-03-06 15:29 -0800
Message-ID<tu5t0h$3mdk$1@dont-email.me>
In reply to#89467
On 3/5/2023 8:52 PM, Bonita Montero wrote:
> Am 05.03.2023 um 22:37 schrieb Chris M. Thomasson:
> 
>> There is nothing wrong with using a race-detector. ...
> And there's noting wrong to buy a supercomputer to proof that
> one plus one is two.
> 

Huh? I think you missed my point.

[toc] | [prev] | [next] | [standalone]


#89499

From"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>
Date2023-03-06 15:42 -0800
Message-ID<tu5tog$3mdk$2@dont-email.me>
In reply to#89467
On 3/5/2023 8:52 PM, Bonita Montero wrote:
> Am 05.03.2023 um 22:37 schrieb Chris M. Thomasson:
> 
>> There is nothing wrong with using a race-detector. ...
> And there's noting wrong to buy a supercomputer to proof that
> one plus one is two.
> 

for instance.. Some code that is "trivial" to me, still deserved to be 
implemented in Relacy first:

https://pastebin.com/raw/f71480694

;^)

[toc] | [prev] | [next] | [standalone]


Page 3 of 4 — ← Prev page 1 2 [3] 4  Next page →

Back to top | Article view | comp.lang.c++


csiph-web