Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #85582
| From | Bo Persson <bo@bo-persson.se> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: Multithreaded Programming : Always use spinlocks for performance? |
| Date | 2022-07-24 15:53 +0200 |
| Message-ID | <jk517uFkkv5U1@mid.individual.net> (permalink) |
| References | <ccb52fa0-5627-4002-8697-d577b90dab1bn@googlegroups.com> |
On 2022-07-24 at 15:31, Frederick Virchanza Gotham wrote: > > I would post this post to a more generic group like "comp.programming.threads" however it's overrun with spam. > > Earlier this week I posted on "comp.lang.c++" about a class I'd written to get a main thread and 8 worker threads to cooperate with each other. > > I've been doing some testing, and I've tested it 3 ways: > (1) Using spinlocks > (2) Using one semaphore, one mutex and one condition_variable > (3) Using two semaphores per worker thread (i.e. 16 semaphores) > > The slowest is No. 2. I haven't identified the exact reason why yet, but it's about 30 times slower than the other two ways. > > No. 3 is quite good, but not the best. > > No. 1 is the fastest. Is this to be expected? Is the only drawback of using spinlocks that they hog the CPU and so the operating system will be a big laggy? > > So if you don't mind the CPU fan getting a bit load and the OS getting a big laggy, are you best to use spinlocks in your multi-threaded programs? > A spinlock can be good if it is almost always free. It is low cost to just test it, and continue without spinning. A spinlock is really bad if there is a 100 threads spinning on it. As most of the time with software, there is no simple rule that always works. Rather usually "it depends".
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Multithreaded Programming : Always use spinlocks for performance? Frederick Virchanza Gotham <cauldwell.thomas@gmail.com> - 2022-07-24 06:31 -0700
Re: Multithreaded Programming : Always use spinlocks for performance? Bo Persson <bo@bo-persson.se> - 2022-07-24 15:53 +0200
Re: Multithreaded Programming : Always use spinlocks for performance? Bonita Montero <Bonita.Montero@gmail.com> - 2022-07-24 16:42 +0200
Re: Multithreaded Programming : Always use spinlocks for performance? Paavo Helde <eesnimi@osa.pri.ee> - 2022-07-24 18:09 +0300
Re: Multithreaded Programming : Always use spinlocks for performance? Bonita Montero <Bonita.Montero@gmail.com> - 2022-07-24 17:41 +0200
Re: Multithreaded Programming : Always use spinlocks for performance? Frederick Virchanza Gotham <cauldwell.thomas@gmail.com> - 2022-07-24 09:20 -0700
Re: Multithreaded Programming : Always use spinlocks for performance? Paavo Helde <eesnimi@osa.pri.ee> - 2022-07-24 19:34 +0300
Re: Multithreaded Programming : Always use spinlocks for performance? Bonita Montero <Bonita.Montero@gmail.com> - 2022-07-24 18:57 +0200
Re: Multithreaded Programming : Always use spinlocks for performance? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-07-24 11:38 -0700
Re: Multithreaded Programming : Always use spinlocks for performance? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2022-07-24 13:17 -0700
Re: Multithreaded Programming : Always use spinlocks for performance? Öö Tiib <ootiib@hot.ee> - 2022-07-25 03:21 -0700
Re: Multithreaded Programming : Always use spinlocks for performance? Bonita Montero <Bonita.Montero@gmail.com> - 2022-07-24 19:01 +0200
Re: Multithreaded Programming : Always use spinlocks for performance? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2022-07-24 13:20 -0700
Re: Multithreaded Programming : Always use spinlocks for performance? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2022-07-24 16:55 -0700
csiph-web