ВходНаше всё Теги codebook 无线电组件 Поиск Опросы Закон Суббота
20 апреля
793038 Топик полностью
Petrovich (09.11.2017 12:33, просмотров: 1) ответил SciFi на Петрович набросил и устранился. Атомарность нужна редко. Чаще всего можно выкрутиться при помощи volatile.
Да я думал неинтересно народу... Надеюсь, вы поняли откуда появляется ошибка. Это, оказывается, всего лишь ошибка наблюдателя. Выход - проверять в обратной поледовательности чем инкремент, т.е. if(tail>head) {out ERROR;} и будет хорошо. Analogy to the rescue. Imagine some bratty kid playing polo while his uptight father looks on with a starched collar and monocle (which can only see one thing at a time, and not even very well, dontcha know). The kid smacks the ball, and then gallops after it, and so on. Now the squinting, snobby father first finds the ball, then looks around for his sproggen. But! If in the meantime, the kid hits it and takes off after it, Dad will find the kid ahead of where he first found the ball. Dad doesn't realize the ball has moved, and concludes that his budding athlete is ahead of the ball, and running the wrong way! If, however, Dad finds the kid first, and then the ball, things will always appear in the right order, if not the right place. The order of action (move ball, move kid) has to be the opposite from the order of observation (find kid, find ball).