Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

NOP

Name: Anonymous 2010-05-13 18:05

What are the differences between
while (condition);
and
while (condition) asm("nop");
?

Name: Anonymous 2010-05-13 21:31

>>4
A function can return different results each time it is called (that mean's it's not a functional function... that is, it relies of side-effects), of course, the arguments themselves can change within the condition as well. Here's a practical example:
while(is_data_processed()) sleep(1);
That could would pause/yield(not wasting much CPU cycles) the current thread, until some data is done processing. Of course, real OSes might have more specialized APIs for async events (here's a Windows example):
WaitForSingleObject(hEvent,INFINITE)
In that case, the thread would be yielded indefinetly until the event is signaled (which would cause that thread to be switched to (eventually) and that function returning). The second example is slightly less wasteful on CPU cycles, but the first one isn't that bad either (unless is_data_processed() is something very CPU intensive, which it shouldn't be).

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List