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


Groups > comp.lang.c > #138721

Re: Multithreading

From Joey Pabalinas <joeypabalinas@gmail.com>
Newsgroups comp.lang.c
Subject Re: Multithreading
Date 2018-12-17 12:45 -1000
Organization A noiseless patient Spider
Message-ID <20181217224512.4obcbjmurozpmfqb@gmail.com> (permalink)
References <5c16c53f.660858109@news.xmission.com> <slrnq1g86m.1p1h.grahn+nntp@frailea.sa.invalid>

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

On Mon, Dec 17, 2018 at 10:19:02PM +0000, Jorgen Grahn wrote:
> On Sun, 2018-12-16, Scott wrote:
> > Well, not specifically a C matter, but as I've made a project of
> > converting an older program to leverage modern multi-core processors,
> > it just happens to be in C and I just happen to have opted for
> > pthreads since that works on all the platforms I use.
> >
> > What I'd like to ask for are recommendations on resources for learning
> > about the principles and pitfalls of threaded programming, in a
> > general way, not tied to any specific implementation. I'm muddling my
> > way through this exercise, but I have this feeling that I'm taking a
> > Sunday stroll through a live minefield and just haven't managed to
> > walk into anything really interesting yet.
> >
> > As always, thanks very much for your help.
> 
> In what way would this program benefit from being threaded?
> 
> The main thing I've learned about threading is to avoid it if
> possible.  Or, to know why you're using it.
> 
> Sorry if that sounded negative.  Put differently, if you can describe
> the task and people can help you with the high-level threading design
> for that particular task, that's better than any pthreads-specific
> help.

As negative as it may sound, I agree that it's one of the most important
considerations to keep in mind when planning a threaded program.

Synchronization (locking, memory barriers, etc.) is far from free. Even
if you ignore the complexity cost they add (not trivial to put it lightly),
it's easier than you think to end up with a program which multi-threaded is
now _slower_ than single, solely because of subtle interactions between
caches, CPU schedulers, and other hard-to-reason-about factors.

This isn't to say it is never a good idea; in many cases it makes sense to
have multiple threads of execution in today's workloads. Just think long and
hard before you commit to that road, and when you do decide on it make sure
you do it right. Your sanity will thank you later.

-- 
Cheers,
Joey Pabalinas

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


Thread

Multithreading nobody@example.org (Scott) - 2018-12-16 21:48 +0000
  Re: Multithreading Joey Pabalinas <joeypabalinas@gmail.com> - 2018-12-16 17:11 -1000
  Re: Multithreading rbowman <bowman@montana.com> - 2018-12-16 21:00 -0700
  Re: Multithreading Jorgen Grahn <grahn+nntp@snipabacken.se> - 2018-12-17 22:19 +0000
    Re: Multithreading Joey Pabalinas <joeypabalinas@gmail.com> - 2018-12-17 12:45 -1000
    Re: Multithreading nobody@example.org (Scott) - 2018-12-19 19:48 +0000
      Re: Multithreading fir <profesor.fir@gmail.com> - 2018-12-19 11:58 -0800
      Re: Multithreading Jorgen Grahn <grahn+nntp@snipabacken.se> - 2018-12-19 23:17 +0000
        Re: Multithreading "Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid> - 2018-12-19 15:31 -0800
          Re: Multithreading "Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid> - 2018-12-19 15:34 -0800
        Re: Multithreading nobody@example.org (Scott) - 2018-12-22 10:43 +0000
          Re: Multithreading fir <profesor.fir@gmail.com> - 2018-12-22 03:41 -0800
            Re: Multithreading fir <profesor.fir@gmail.com> - 2018-12-22 03:46 -0800
          Re: Multithreading Thiago Adams <thiago.adams@gmail.com> - 2018-12-22 07:14 -0800
          Re: Multithreading rbowman <bowman@montana.com> - 2018-12-22 11:41 -0700
            Re: Multithreading "Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid> - 2018-12-22 16:09 -0800
          Re: Multithreading scott@slp53.sl.home (Scott Lurndal) - 2018-12-22 19:52 +0000
            Re: Multithreading "Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid> - 2018-12-22 16:10 -0800
            Re: Multithreading nobody@example.org (Scott) - 2018-12-23 23:11 +0000
              Re: Multithreading "Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid> - 2018-12-23 15:24 -0800
                Re: Multithreading "Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid> - 2018-12-23 15:25 -0800
                Re: Multithreading fir <profesor.fir@gmail.com> - 2018-12-24 02:05 -0800
              Re: Multithreading fir <profesor.fir@gmail.com> - 2018-12-24 02:08 -0800
  Re: Multithreading fir <profesor.fir@gmail.com> - 2018-12-18 07:18 -0800
    Re: Multithreading fir <profesor.fir@gmail.com> - 2018-12-18 07:51 -0800
      Re: Multithreading fir <profesor.fir@gmail.com> - 2018-12-19 09:24 -0800
        Re: Multithreading fir <profesor.fir@gmail.com> - 2018-12-19 09:55 -0800
          Re: Multithreading fir <profesor.fir@gmail.com> - 2018-12-19 11:02 -0800
            Re: Multithreading fir <profesor.fir@gmail.com> - 2018-12-19 11:16 -0800
              Re: Multithreading fir <profesor.fir@gmail.com> - 2018-12-19 11:25 -0800
          Re: Multithreading "Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid> - 2018-12-19 15:37 -0800
            Re: Multithreading fir <profesor.fir@gmail.com> - 2018-12-19 16:03 -0800
              Re: Multithreading fir <profesor.fir@gmail.com> - 2018-12-20 08:02 -0800

csiph-web