Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Ian Collins Newsgroups: comp.lang.c Subject: Re: Default values in #define Date: Sun, 28 Aug 2016 08:41:46 +1200 Lines: 31 Message-ID: References: <502669cd-f0fc-4b99-8c8a-0d806c8b5f20@googlegroups.com> <11e2bb75-ee3c-4904-b7c8-77023426fb45@googlegroups.com> <87vaynj0l9.fsf@bsb.me.uk> <4c14769d-f75d-4c8f-89f6-5290f6b97b32@googlegroups.com> <87poovitqy.fsf@bsb.me.uk> <62672946-dc1f-4d94-9c33-5434f51da85d@googlegroups.com> <71637eed-ce54-4950-9568-d053ff0abc84@googlegroups.com> <91a99d84-b481-4dae-949b-914cb5e8aab7@googlegroups.com> <60c8cdba-0914-430a-999d-5543e627025e@googlegroups.com> <2d96b3c5-8c6d-4aa5-a6f1-d6381a533e24@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net ZHz++z+hiJRZX9odO0XfWAizIcUMhWgGnazqV5wm8lI3cceSKF Cancel-Lock: sha1:n7G8L4D/YT1fWBZtmtX7equxPPY= User-Agent: Mozilla/5.0 (X11; SunOS i86pc; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 In-Reply-To: <2d96b3c5-8c6d-4aa5-a6f1-d6381a533e24@googlegroups.com> Xref: csiph.com comp.lang.c:92820 On 08/28/16 08:10 AM, supercat@casperkitty.com wrote: > > If there are two threads with similar code, that design is clearly broken. > Some similar designs, however, can be perfectly workable if a system has > memory barriers around compiler accesses, or if everything that is used > in the interrupt and mainline is "volatile" [note that memory barriers are > often less costly than requiring that everything be volatile]. > > For example: > > volatile interrupt_item_count; > > MAINLINE: > while(interrupt_item_count) > spin(); > ... store data into an array > ... set pointer to start of array > interrupt_item_count = number_of_items; > > INTERRUPT: > if (interrupt_item_count) > { > OUTPUT_DEVICE = *interrupt_data_ptr++; > interrupt_item_count--; > } Why would you resort to such a scheme when there are standard (or obvious target specific) tools for the job? -- Ian