Jump to content

Talk:Busy waiting: Difference between revisions

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
Content deleted Content added
Line 10: Line 10:
:::Specifically, multi-core machines (which are now ubiquitous) negate the assumption that even single-byte reads and writes are atomic, as the processors do not necessarily share caches. <span style="font-size: smaller;" class="autosigned">—Preceding [[Wikipedia:Signatures|unsigned]] comment added by [[Special:Contributions/68.103.216.128|68.103.216.128]] ([[User talk:68.103.216.128|talk]]) 01:44, 25 March 2011 (UTC)</span><!-- Template:UnsignedIP --> <!--Autosigned by SineBot-->
:::Specifically, multi-core machines (which are now ubiquitous) negate the assumption that even single-byte reads and writes are atomic, as the processors do not necessarily share caches. <span style="font-size: smaller;" class="autosigned">—Preceding [[Wikipedia:Signatures|unsigned]] comment added by [[Special:Contributions/68.103.216.128|68.103.216.128]] ([[User talk:68.103.216.128|talk]]) 01:44, 25 March 2011 (UTC)</span><!-- Template:UnsignedIP --> <!--Autosigned by SineBot-->


This code is ''''''broken.'''''' (It would be bad practice even if it was correct, which it is not.) There is NO operation in C++ that is guaranteed atomic. One must either use the atomic types defined in the standard library of C++11, or if those are not yet available to you, roll your own using operating-system specific routines like InterlockedIncrement and InterlockedExchange on Windows. The purpose of "volatile" is to tell the compiler not to optimize away operations on the variable which appear to be redundant. [[User:Jive Dadson|Jive Dadson]] ([[User talk:Jive Dadson|talk]]) 03:06, 19 August 2012 (UTC)
This code is '''''broken.''''' (It would be bad practice even if it was correct, which it is not.) There is NO operation in C++ that is guaranteed atomic. One must either use the atomic types defined in the standard library of C++11, or if those are not yet available to you, roll your own using operating-system specific routines like InterlockedIncrement and InterlockedExchange on Windows. The purpose of "volatile" is to tell the compiler not to optimize away operations on the variable which appear to be redundant. [[User:Jive Dadson|Jive Dadson]] ([[User talk:Jive Dadson|talk]]) 03:06, 19 August 2012 (UTC)


== Polling Discussion and interrupts ==
== Polling Discussion and interrupts ==

Revision as of 03:08, 19 August 2012

WikiProject iconComputer science Start‑class Low‑importance
WikiProject iconThis article is within the scope of WikiProject Computer science, a collaborative effort to improve the coverage of Computer science related articles on Wikipedia. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks.
StartThis article has been rated as Start-class on Wikipedia's content assessment scale.
LowThis article has been rated as Low-importance on the project's importance scale.
Things you can help WikiProject Computer science with:

Volatile Reference

This page is referenced by the volatile variable page: "For an example of the use of volatile in context, see Busy waiting." However, volatile variable also mentions that "In C and C++, volatile was not intended, and it is not implemented on all systems, to be a correct or useful synchronization primitive." The code example on this page does seem to be using the volatile variable 'i' as a synchronization primitive; will the example code actually work all the time? If not, should we find a different primitive to use for synchronizing the example code? Since the example code already uses pthreads, maybe something from pthreads? 134.173.66.78 (talk) 02:59, 30 January 2009 (UTC)[reply]

The reason for not using "volatile" as a synchronization primitive is that you can't count on memory reads or writes being atomic -- if you're looking for a transition from 0xFFFF to 0xFF00, and the other process writes 0x0000 in two byte-sized chunks, you might get a false positive depending on the order in which the bytes are written. In the example in the article, it's not wrong, merely bad practice. --Carnildo (talk)
Volatile does NOT enforce atomic variable access in C and C++. The code is just *wrong* — Preceding unsigned comment added by Axelgneiting (talkcontribs) 17:28, 8 February 2011 (UTC)[reply]
Specifically, multi-core machines (which are now ubiquitous) negate the assumption that even single-byte reads and writes are atomic, as the processors do not necessarily share caches. —Preceding unsigned comment added by 68.103.216.128 (talk) 01:44, 25 March 2011 (UTC)[reply]

This code is broken. (It would be bad practice even if it was correct, which it is not.) There is NO operation in C++ that is guaranteed atomic. One must either use the atomic types defined in the standard library of C++11, or if those are not yet available to you, roll your own using operating-system specific routines like InterlockedIncrement and InterlockedExchange on Windows. The purpose of "volatile" is to tell the compiler not to optimize away operations on the variable which appear to be redundant. Jive Dadson (talk) 03:06, 19 August 2012 (UTC)[reply]

Polling Discussion and interrupts

Discussing shortly the concepts polling (computer science) and Interrupt would be a great addition to this article, in my eyes, as they bear similar issues. --Abdull 17:42, 7 November 2005 (UTC)[reply]

I added the merge suggestion as the polling and busy waiting articles don't explain the differences between both techniques. --Abdull 00:53, 22 November 2006 (UTC)[reply]
This is programming jargon. While the concepts may be similar, the terminology is used for specific circumstances. Busy waiting generally applies to cpu scheduling, while polling refers mainly to input devices. It simply does not make sense to say that you "polled the cpu" or "busy waited on the mouse".

Example

nice to see you, 'while true do skip':

while (i==0) {}

Non-Unix Explanation

Someone needs to explain the use of uptime for non-Unix folks. 218.102.220.129 12:17, 24 May 2006 (UTC)[reply]