I am working with bitcion version < ver. 0.13.0 which contains the setgenerate true functionallity. I could see in some situations during minning process that when I find a solution, but the other miner has found it already before (and its already published), I get the message: "ERROR: BitcoinMiner: generated block is stale". My question is: why the minning process on a specific block not interrupted at the moment when a solution found by one of the other miners?
A realistic bitcoin miner finishes a work unit in less than a second and blocks are only found every ten minutes. So interrupting a work unit would increase mining efficiency by something like 0.1% at best. The additional hardware required to support such interruption on a realistic mining platform would not justify the small performance improvement you might get.
However, it is still beneficial to switch to a new work unit as quickly as possible when a new block is found. But in modern mining systems, this is implemented at a higher level, typically somewhere between the miner's end of the connection to the mining pool and the mining hardware itself.
You can think of it as the software controlling the actual mining hardware having a "big" work unit and, from it, doling out "smaller" work units to individual mining hardware units. When a new block is found, the software gets a new "big" work unit from the mining pool and when the mining hardware needs a new smaller work unit, it gets one from the new big work unit. It's counterproductive, because the small work units are already so small (typically only a few billion hash operations) to try to interrupt them.