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


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

Re: good reference on threads

From Paavo Helde <myfirstname@osa.pri.ee>
Newsgroups comp.lang.c++
Subject Re: good reference on threads
Date 2021-06-11 14:03 +0300
Organization A noiseless patient Spider
Message-ID <s9vfug$rd8$1@dont-email.me> (permalink)
References <s9u208$94h$2@dont-email.me> <cf233b93-519a-4987-ae48-7831b2d55179n@googlegroups.com> <s9uee1$bk0$1@dont-email.me>

Show all headers | View raw


11.06.2021 04:31 Lynn McGuire kirjutas:
> 
> I want multiple threads to share the massive dataset that we use.  Very 
> tricky, I have tried sharing data between the threads and it was a 
> disaster.

MFC is not thread-safe, so only the main thread can call any MFC functions.

For data exchange the most robust way is to use a couple of message 
queues for passing events back and forth between the threads. Any data 
which is not MT-safe to access should be copied by value into a new 
non-shared object when putting into the queue.

One can easily build such a queue with a std::queue and a std::mutex.

For example, if a background queue wants to display a message to the 
user, it can send an event to the main thread queue containing the 
message. The main thread would check in a MFC OnIdle() function if there 
are any events in the queue, and process them in the main thread.

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


Thread

good reference on threads Lynn McGuire <lynnmcguire5@gmail.com> - 2021-06-10 16:59 -0500
  Re: good reference on threads Öö Tiib <ootiib@hot.ee> - 2021-06-10 15:49 -0700
    Re: good reference on threads Öö Tiib <ootiib@hot.ee> - 2021-06-10 17:58 -0700
    Re: good reference on threads Lynn McGuire <lynnmcguire5@gmail.com> - 2021-06-10 20:31 -0500
      Re: good reference on threads Öö Tiib <ootiib@hot.ee> - 2021-06-10 20:31 -0700
        Re: good reference on threads "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-06-10 21:32 -0700
          Re: good reference on threads "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-06-10 21:33 -0700
      Re: good reference on threads Ian Collins <ian-news@hotmail.com> - 2021-06-11 20:17 +1200
        Re: good reference on threads Lynn McGuire <lynnmcguire5@gmail.com> - 2021-06-11 14:13 -0500
      Re: good reference on threads Paavo Helde <myfirstname@osa.pri.ee> - 2021-06-11 14:03 +0300
        Re: good reference on threads Paavo Helde <myfirstname@osa.pri.ee> - 2021-06-11 15:19 +0300
        Re: good reference on threads "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-06-12 14:41 -0700
  Re: good reference on threads Lynn McGuire <lynnmcguire5@gmail.com> - 2021-06-10 22:03 -0500
    Re: good reference on threads "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-06-10 20:08 -0700
      Re: good reference on threads Lynn McGuire <lynnmcguire5@gmail.com> - 2021-07-01 22:27 -0500
        Re: good reference on threads "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-07-01 21:28 -0700
        Re: good reference on threads legalize+jeeves@mail.xmission.com (Richard) - 2021-07-27 01:21 +0000
    Re: good reference on threads Cholo Lennon <chololennon@hotmail.com> - 2021-06-12 23:06 -0300
      Re: good reference on threads Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-06-12 21:47 -0700
        Re: good reference on threads Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-06-12 21:49 -0700
    Re: good reference on threads legalize+jeeves@mail.xmission.com (Richard) - 2021-07-27 01:19 +0000
    Re: good reference on threads Bonita Montero <Bonita.Montero@gmail.com> - 2021-07-27 03:58 +0200

csiph-web