-3

i've understood that since other processors can reach the shared data in multiprocessor system even when interrupts are disabled, we implement spinlock for the synchronization of multiprocessor systems

but the textbooks says if interrupts aren't disabled for multiprocessor system synchronization (only the spinlocks are implemented, not "disabling interrupts"), resources may be taken by other processors. So disabling interrupts is also essential in multiprocessor system synchronization

i don't get why we still have to disable interrupts for multiprocessor systems can anyone answer my question please?

  • 1
    This question looks like it was put together by a computer with a combination of random words taken from multithreading thesaurus. – SergeyA Apr 15 '16 at 13:48
  • @SergeyA I think there's a combination of language barrier (which I hope OP can help us overcome!) and confusion about the terms involved. – Marcus Müller Apr 15 '16 at 13:53
  • Possible duplicate of [what is meant by disabling interrupts?](https://stackoverflow.com/questions/3427546/what-is-meant-by-disabling-interrupts) – Kindred Dec 25 '18 at 05:22

2 Answers2

1

Even single processor systems disable interrupts for synchronization. That is the prime method of serialization for an operating system.

When you acquire spinlocks, do your work as quickly as possible, then release.

If you do not block interrupts, you could acquire a spinlock then get interrupted.

Your text seems to be suggesting that interrupts are disabled on all processors. That is not [always] the case.

user3344003
  • 20,574
  • 3
  • 26
  • 62
  • i am wondering whether i am understanding what you mean clearly or not. Is the need to block the interrupts is if one of the processors' process(let's say A) acquire a spinlock then get interrupted, the process goes into the blocked state, so if the other processors' process(B) tries to access into the critical section, it has to wait for the process A to come back to the running state and exit the spinlock and it would result an overhead? – Sukjun Hwang Apr 16 '16 at 14:50
  • In theory, the processor could block itself trying to acquire a spinlock it already has. It can also add to the time the spin lock is held. – user3344003 Apr 16 '16 at 15:31
0

but the textbooks says if interrupts aren't disabled for multiprocessor system synchronization (only the spinlocks are implemented, not "disabling interrupts"), resources may be taken by other processors. So disabling interrupts is also essential in multiprocessor system synchronization

It's not rare for textbooks to over-simplify.

You can, depending on your CPU architecture, of course implement a system where interrupts aren't disabled – in fact, you'll find your multi-core PC to have interrupts enabled and work quite well.

But that of course demands your understanding of shared state, preemption and priority inversion is even better than just for multithreaded single-core machines. Disabling all interrupts is really a poor man's solution here, and your text book might not portray a best-practice solution.

Marcus Müller
  • 34,677
  • 4
  • 53
  • 94
  • I am not even sure what interrupts OP is talking about. Any preemptive OS is based on iterrupts and won't work without them. – SergeyA Apr 15 '16 at 13:49
  • @SergeyA yes; but I remember many "hobbyist" books' introductions to multitasking on microcontrollers (also, the typical minimal example for writing a preemption-save ISR on a MCU with Interrupt priority handling, sadly; it seems microcontroller companies like to let their interns write examples) is to disable interrupts before critical code passages (typically, things like waiting for another core to complete its work), and activating after. It's terrible, it's bad practice, it's breaking real-time, and modern CPUs support much better approaches to this, but it's still widely preached. – Marcus Müller Apr 15 '16 at 13:52
  • Interesting! I admit, I never read any of those books (and never programmed for MCU), so I was not even understanding what OP might be talking about. Now at least it makes half sense, thanks! – SergeyA Apr 15 '16 at 13:54
  • it seems like i've over simplified the concept just by myself.. thanks a lot! – Sukjun Hwang Apr 16 '16 at 14:44