Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: andrew@cucumber.demon.co.uk (Andrew Gabriel) Newsgroups: comp.programming.threads Subject: Re: Can I get code review for some shared memory RPC code? Date: Sun, 10 Aug 2014 15:45:58 +0000 (UTC) Organization: A noiseless patient Spider Lines: 26 Sender: andrew@a20 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Date: Sun, 10 Aug 2014 15:45:58 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="564b18614511828cf2a82c5cd4db0afd"; logging-data="9349"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+rdB/YEudnw0VMOCGaxtmCTbRRLaNXbpI=" X-Newsreader: knews 1.0c.0 Cancel-Lock: sha1:0XqcrZ1PEjQUACkeUxAn4x9PSgw= Xref: csiph.com comp.programming.threads:2571 In article , Steven Stewart-Gallus writes: > The code should be fairly portable (at least with futex use disabled). > Of course, I'm using POSIX threads as C11 threads aren't widely > implemented. I have absolutely zero experience doing any sort of > complicated multithreaded programming with atomics (I prefer to stick > to isolated heaps and very simple message queues) so the code is > probably broken in some way. One thing that doesn't help is that I > can only test on x86 right now (which has a very strong memory model). > Annoyingly, there's no portable pause intrinsic but it should be > really easy to s/_mm_pause/my_pause/g for a different architecture. 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. 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. I did not look at the program logic in detail, as you didn't describe what you intended it to do. -- Andrew Gabriel [email address is not usable -- followup in the newsgroup]