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


Groups > comp.lang.c > #138924

Re: Multithreading

From "Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid>
Newsgroups comp.lang.c
Subject Re: Multithreading
Date 2018-12-22 16:09 -0800
Organization n/a
Message-ID <pvmjo8$gap$1@dont-email.me> (permalink)
References (1 earlier) <slrnq1g86m.1p1h.grahn+nntp@frailea.sa.invalid> <5c1a999a.911828906@news.xmission.com> <slrnq1lkbj.1p1h.grahn+nntp@frailea.sa.invalid> <5c1e08e6.1136929031@news.xmission.com> <g87enoF6pd6U1@mid.individual.net>

Show all headers | View raw


On 12/22/2018 10:41 AM, rbowman wrote:
> On 12/22/2018 03:43 AM, Scott wrote:
>> For feeding the threads, a shared job queue seems right. I made a
>> simple queue with mutex locking, since it's not a big player in the
>> overall process. The way it's laid out, a few thousand jobs can
>> account for many minutes of run time. On the output side there's no
>> contention to worry about.
> 
> Is there any i/o involved, disk accesses for example? What does the CPU 
> usage look like on each of the cores? If you are on Linux gprof is easy 
> to use and might give you some hints. There are commercial tools like 
> TotalView that are shinier.
> 
> On Windows VS has some capability. Rational's Purify is not cheap and 
> it's also painful enough that we used it very rarely.
> 
> Do the threads ever come up for air? You may need to throw sched_yield() 
> in some strategic places to allow the other threads to run. Context 
> switching is expensive however.

Generally, one should never use sched_yield() just to get "other threads 
to run". Threads should run full steam ahead doing work.  However, 
sched_yield() and hardware specific yields (e.g., x86 PAUSE) can be used 
in some spinlock backoff schemes. A nice example is the adaptive version 
of a mutex is where a thread can spin a few times before finally 
blocking on a kernel waitset.


> Keep the TANSTAAFL principle in mind. N cpu intensive threads on one 
> core aren't going to have any magical way to get more cycles than there 
> are.

You usually want each thread to represent an independent unit of 
execution. 4 CPUS, you can create 4 threads. Even use affinity masks to 
bind them. Or, you can "oversubscribe" with 8 threads, 2-per core.

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