how the HECK do interrupts work. shouldn't they halve the efficiency of any given program? since it has to check if the interrupt is active on every cycle. this isn't covered in the k&r book
>>59246013
Programs don't check for interrupts.
Your operating system is responsible for managing interrupts.
Interrupts aren't checked for every cycle, they're enabled and disabled. If an interrupt is attempted and blocked then it queues up. If you're a big dick then you can write code that permanently disables interrupts letting you lock a processor. This is generally prevented by some extra permissions.
read the book luke
i hope you aren't learning C from k&r, unless you're into bdsm
>>59246143
i don;t use an operating system im programming an avr (。>﹏<。)
how does it "manage" them without checking every cycle to see if the pin is active?
>>59246172
>If an interrupt is attempted and blocked then it queues up.
Wrong.
When an interrupt occurs, the interrupt line is just simply held high until it is serviced.
If you ignore the interrupt and another interrupt comes in, then you have missed the last interrupt.
That's why you should only disable interrupts for very short amounts of time, so that you only defer the handling of the interrupt rather than missing any.
Interrupts need to be handled as soon as possible or else they're lost.
>>59246186
In that case interrupts are handled in hardware by your processor.
>>59246209
that's what i don't get, though. if it is executing a command, and monitoring for input, how can it do both on the same cycle? it's only got one core
>>59246206
not him but you can "service" an interrupt by picking it up and just dropping it onto a queue, right?
that way you don't lose anything
>>59246013
>>59246186
>>59246139
This thread will be pruned a couple hours from now when /g/ mods finally wake up
But no, that's not how it works
>>59246228
Yes, you can. But interrupts technically aren't disabled, you're just deferring their handling.
Your queue must be able to insert into some kind of list right? inserting into the list must be atomic, or else another interrupt coming in while you're in the middle of inserting could thoroughly fuck things up.
You obviously can't use a mutex/splinlock in an interrupt handler so the only thing you can do is temporarily disable interrupts while inserting to defer any interrupt that may come in during that time.
>>59246227
It checks your pin every cycle.
>fetch
>decode
>execute
>process interrupts
There aren't any additional costs performance-wise because it's implemented in hardware.
>>59246259
I see, that makes sense. I didn't think about the atomicity requirement, which is important because the CPU can call your interrupt handler anytime.
If the interrupt line gets realy congested and some interrupt requests are lost, do those hardware devices just try again after a set interval?
>>59246305
ah ha. so checking that pin for input is part of the processor's architecture? i guess that functionality just isn't used if you have that pin defined as an output?
>>59246371
cute tomato knees !!!
>>59246013
Maki too fat in this picture. Delet- this
>>59246381
I think her sweater is just a bit big anon.
>>59246013
Maki
>>59246548
maki!