Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.programming.threads > #2572
| Newsgroups | comp.programming.threads |
|---|---|
| Date | 2014-08-10 20:57 -0700 |
| References | <e10e88a1-5526-4257-9053-c98b49fa31ed@googlegroups.com> <ls843m$945$1@dont-email.me> |
| Message-ID | <45f15ddc-9fdc-4e0e-a2b6-2e72e2bd52ed@googlegroups.com> (permalink) |
| Subject | Re: Can I get code review for some shared memory RPC code? |
| From | Steven Stewart-Gallus <stevenselectronicmail@gmail.com> |
> Your wait_until_different and hint_wakeup should be replaced by a > condition variable (cond_wait, and cond_signal or cond_broadcast). > Then the need for your pause function and spin loop go away. Condition variables are implemented in terms of the futex system call (on Linux only obviously). I am reimplementing my own concurrency primitives in terms of the lowest level OS primitives for performance reasons and for learning experience. If I used the condition variables provided by GLibc it'd be highly likely that I'd still be using spin loops, they'd just be hidden inside of GLibc. As well, when built with futexes enabled the code only spins for a small amount of time and waits in a kernel wait queue otherwise. I'm honestly kind of offended because you seemed to have posted a very silly comment without taking the time to learn a bit about the type of code you were reviewing first. > I don't know how portable the atomic_* functions are that you are > using. I would use a mutex protected variable, which should work > everywhere, if portability is important. stdatomic.h is part of the C11 standard's new functionality for multithreading. I'm honestly surprised that a poster on comp.programming.threads doesn't know about stdatomic.h or can't bother to look it up. The futex system call is obviously unportable but it is hidden behind a define. _mm_pause is an Intel intrinsic and is obviously nonportable but it should be easy to find a platform equivalent for any one that I need to port to. It's very amusing that you go on to recommend to use a mutex protected variable as only the atomics part of the C11 standard is very widely implemented, and POSIX mutexes and condition variables are not portable to Windows. Moreover, POSIX mutexes and condition variables are unlikely to be portable to embedded platforms or other specialized hardware. atomic_* functions are probably MORE portable than using any libraries implementations of mutex. Besides, for performance I need my own custom implementation in terms of the lowest level primitives. > I did not look at the program logic in detail, as you didn't describe > what you intended it to do. What's left to say? I'm implementing Shared Memory Remote Procedure Calls between two tasks.
Back to comp.programming.threads | Previous | Next — Previous in thread | Find similar | Unroll thread
Can I get code review for some shared memory RPC code? Steven Stewart-Gallus <stevenselectronicmail@gmail.com> - 2014-08-08 19:17 -0700
Re: Can I get code review for some shared memory RPC code? andrew@cucumber.demon.co.uk (Andrew Gabriel) - 2014-08-10 15:45 +0000
Re: Can I get code review for some shared memory RPC code? Steven Stewart-Gallus <stevenselectronicmail@gmail.com> - 2014-08-10 20:57 -0700
csiph-web