EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

The idea of disabling interrupts

Started by karthikbalaguru November 29, 2007
Hi,

Is it a good idea to disable interrupts while sharing data (Critical
Sections) ?

Thx in advans,
Karthik Balaguru

On Nov 29, 2:56 pm, karthikbalaguru <karthikbalagur...@gmail.com>
wrote:
> Hi, > > Is it a good idea to disable interrupts while sharing data (Critical > Sections) ? > > Thx in advans, > Karthik Balaguru
Not really, why not locks (semaphore, signal etc. ) for shared data rather disabling the interrupts. ali
karthikbalaguru wrote:

> Is it a good idea to disable interrupts while sharing data (Critical > Sections) ?
If you're sharing your data with an ISR, it is often the only thing you can do (unless your CPU has the right atomic instructions for the job). If you're sharing between two tasks, it depends. Generally, if you disable interrupts for a short period, and you don't call any OS/library functions, it can be a useful method. Exactly how long you can disable interrupts depends on your environment and real-time requirements.
On Nov 29, 12:21 pm, Arlet Ottens <usene...@ladybug.xs4all.nl> wrote:
> karthikbalaguru wrote: > > Is it a good idea to disable interrupts while sharing data (Critical > > Sections) ? > > If you're sharing your data with an ISR, it is often the only thing you > can do (unless your CPU has the right atomic instructions for the job).
Thx for highlighting this :):)
> If you're sharing between two tasks, it depends. Generally, if you > disable interrupts for a short period, and you don't call any OS/library > functions, it can be a useful method. Exactly how long you can disable > interrupts depends on your environment and real-time requirements.
Thx for the info. Interesting :):) Thinking over this, i have a query - Is it possible to do sharing of data(Critcal Section) wihtout diabling of interrupts and also without the use of these RTOS features like semaphore/Mutex/ MessageQueues/Pipes/Mailboxes ? Thx in advans, Karthik Balaguru
karthikbalaguru wrote:

>> If you're sharing between two tasks, it depends. Generally, if you >> disable interrupts for a short period, and you don't call any OS/library >> functions, it can be a useful method. Exactly how long you can disable >> interrupts depends on your environment and real-time requirements. > > Thx for the info. Interesting :):) > > Thinking over this, i have a query - > Is it possible to do sharing of data(Critcal Section) wihtout diabling > of interrupts and also > without the use of these RTOS features like semaphore/Mutex/ > MessageQueues/Pipes/Mailboxes ?
Sometimes you can use atomic instructions, if your CPU has them. For instance, the ARM has the SWP instruction that can be used to solve some concurrency problems. The other possibility is to not use a preemptive RTOS. You can either use a non-preemptive (cooperative) OS, or not use an OS at all. I've implemented quite a few embedded systems that just had a polling loop, and a bunch of ISRs. In some cases, the ISRs did the bulk of the work, so there wouldn't be any concurrency issues, and the timing was guaranteed.
Op Thu, 29 Nov 2007 09:42:34 +0100 schreef karthikbalaguru  
<karthikbalaguru79@gmail.com>:
> On Nov 29, 12:21 pm, Arlet Ottens <usene...@ladybug.xs4all.nl> wrote: >> karthikbalaguru wrote: >> > Is it a good idea to disable interrupts while sharing data (Critical >> > Sections) ? >> >> If you're sharing between two tasks, it depends. Generally, if you >> disable interrupts for a short period, and you don't call any OS/library >> functions, it can be a useful method. Exactly how long you can disable >> interrupts depends on your environment and real-time requirements. > > Thinking over this, i have a query - > Is it possible to do sharing of data(Critcal Section) wihtout diabling > of interrupts and also > without the use of these RTOS features like semaphore/Mutex/ > MessageQueues/Pipes/Mailboxes ?
If you insist on sharing data (instead of transfering), there is also lock-free data exchange. It involves keeping multiple copies of the shared data and updating its pointers depending on the state of the readers and writers. -- Gemaakt met Opera's revolutionaire e-mailprogramma: http://www.opera.com/mail/
On Nov 29, 3:42 am, karthikbalaguru <karthikbalagur...@gmail.com>
wrote:
> On Nov 29, 12:21 pm, Arlet Ottens <usene...@ladybug.xs4all.nl> wrote: > > > karthikbalaguru wrote: > > > Is it a good idea to disable interrupts while sharing data (Critical > > > Sections) ? > > > If you're sharing your data with an ISR, it is often the only thing you > > can do (unless your CPU has the right atomic instructions for the job). > > Thx for highlighting this :):) > > > If you're sharing between two tasks, it depends. Generally, if you > > disable interrupts for a short period, and you don't call any OS/library > > functions, it can be a useful method. Exactly how long you can disable > > interrupts depends on your environment and real-time requirements. > > Thx for the info. Interesting :):) > > Thinking over this, i have a query - > Is it possible to do sharing of data(Critcal Section) wihtout diabling > of interrupts and also > without the use of these RTOS features like semaphore/Mutex/ > MessageQueues/Pipes/Mailboxes ? > > Thx in advans, > Karthik Balaguru
If you have an OS that supports MessageQueues/Pipes/Mailboxes, why do you want to avoid them? And if you have an OS that supports semaphore/Mutex, why would you want to avoid using them? Semaphores were created for dealing with critical section issues.why not use the right tool for the job? Ed.
On Nov 29, 2:15 pm, Arlet Ottens <usene...@c-scape.nl> wrote:
> karthikbalaguru wrote: > >> If you're sharing between two tasks, it depends. Generally, if you > >> disable interrupts for a short period, and you don't call any OS/library > >> functions, it can be a useful method. Exactly how long you can disable > >> interrupts depends on your environment and real-time requirements. > > > Thx for the info. Interesting :):) > > > Thinking over this, i have a query - > > Is it possible to do sharing of data(Critcal Section) wihtout diabling > > of interrupts and also > > without the use of these RTOS features like semaphore/Mutex/ > > MessageQueues/Pipes/Mailboxes ? > > Sometimes you can use atomic instructions, if your CPU has them. For > instance, the ARM has the SWP instruction that can be used to solve some > concurrency problems. > > The other possibility is to not use a preemptive RTOS. You can either > use a non-preemptive (cooperative) OS, or not use an OS at all. I've > implemented quite a few embedded systems that just had a polling loop, > and a bunch of ISRs. In some cases, the ISRs did the bulk of the work, > so there wouldn't be any concurrency issues, and the timing was guaranteed.
Thx for the info. I thought of such a similar idea - The idea of using flags w.r.t interrupts. Enable a flagA and manipulate the part A (shared data) in task code and as flagA is enabled, manipulate the part B in the ISR. And vice versa for part B(Shared Data). Though this replaces the idea of disabling interrupts, this is time consuming. Karthik Balaguru
On Nov 30, 10:11 am, Ed Prochak <edproc...@gmail.com> wrote:
> On Nov 29, 3:42 am, karthikbalaguru <karthikbalagur...@gmail.com> > wrote: > > > > > > > On Nov 29, 12:21 pm, Arlet Ottens <usene...@ladybug.xs4all.nl> wrote: > > > > karthikbalaguru wrote: > > > > Is it a good idea to disable interrupts while sharing data (Critical > > > > Sections) ? > > > > If you're sharing your data with an ISR, it is often the only thing you > > > can do (unless your CPU has the right atomic instructions for the job). > > > Thx for highlighting this :):) > > > > If you're sharing between two tasks, it depends. Generally, if you > > > disable interrupts for a short period, and you don't call any OS/library > > > functions, it can be a useful method. Exactly how long you can disable > > > interrupts depends on your environment and real-time requirements. > > > Thx for the info. Interesting :):) > > > Thinking over this, i have a query - > > Is it possible to do sharing of data(Critcal Section) wihtout diabling > > of interrupts and also > > without the use of these RTOS features like semaphore/Mutex/ > > MessageQueues/Pipes/Mailboxes ? > > > Thx in advans, > > Karthik Balaguru > > If you have an OS that supports MessageQueues/Pipes/Mailboxes, why do > you want to avoid them? > And if you have an OS that supports semaphore/Mutex, why would you > want to avoid using them? > > Semaphores were created for dealing with critical section issues.why > not use the right tool for the job?
I was just thinking of a way of avoiding the disabling of interrupts by our own programming rather than depending on the RTOS features. Karthik Balaguru
On Nov 29, 12:42 am, karthikbalaguru <karthikbalagur...@gmail.com>
wrote:
> On Nov 29, 12:21 pm, Arlet Ottens <usene...@ladybug.xs4all.nl> wrote: > > > karthikbalaguru wrote: > > > Is it a good idea to disable interrupts while sharing data (Critical > > > Sections) ? > > > If you're sharing your data with an ISR, it is often the only thing you > > can do (unless your CPU has the right atomic instructions for the job). > > Thx for highlighting this :):) > > > If you're sharing between two tasks, it depends. Generally, if you > > disable interrupts for a short period, and you don't call any OS/library > > functions, it can be a useful method. Exactly how long you can disable > > interrupts depends on your environment and real-time requirements. > > Thx for the info. Interesting :):) > > Thinking over this, i have a query - > Is it possible to do sharing of data(Critcal Section) wihtout diabling > of interrupts and also > without the use of these RTOS features like semaphore/Mutex/ > MessageQueues/Pipes/Mailboxes ? > > Thx in advans, > Karthik Balaguru
Please define share more precisely. If only one thread is writing to data, and other thread(s) is reading data only, then no need for the things you requested. Producer/ consumer buffers are typically implemented as such.

The 2024 Embedded Online Conference