We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
hello everyone, I am writing a code in which, a variable is used in interrupt routine as well as in while(1) loop I am changing that variable value in interrupt and in while(1) loop I am confused, while handling it how can I avoid clashes occurred in interrupt as well as in while(1) loop
another doubt is, if in c language, I want to change the value in a certain location say 0x1234H then how is it possible?
thank you all take care
i do not think you can do that in c bcoz you need semifores and they are in java only. try looking for java in yahoo.
Semaphores only in Java?
Semaphores are a concept - they are available, one way or another, in a large number of languages.
A semaphore, or critical section, or mutex, ... is not always needed. Most processors have some form of operations that can be performed atomically, without the need for synchronization.
INC @R0 will for example perform an atomic increment of a memory cell, i.e. if both the main loop and an interrupt tries to increment the cell, it will increment twice, without any need for any extra synchronization.
An interrupt that produces data to be used by a thread (producer-consumer) can be implemented as a trivial round-robin buffer, where the producer owns the write pointer, and the consumer owns the read pointer. This means that only the interrupt will modify the write pointer and only the reading task will modify the read pointer. As long as the pointer size is small enough to be updated atomically, no semaphore is needed. An 8-bit processor can always update an 8-bit index atomically. Most 8-bit processors can also atomically update 16-bit data-pointer registers, greatly increasing the possible ring-buffer size.