That's incorrect. This code will only hang a single core machine if there are no interrupts to force context switching (which is the case on the vast majority of machines that run an OS, anyway). Also, this code is useful to spawn a thread that continuously polls hardware. If you have a piece of hardware that can change its output at any given time, but you're not sure when, you can spawn the equivalent to a listener thread to capture (sample) changes at the output. In fact, this code is useful in many "thread listener" type scenarios, such as when a server is idling and listening for clients...
P
Pcube
@Pcube
Posts
-
while (true) and for (; ; ) [modified] -
random unique number [mysql]If you're assigning a random number to every entry in the table (i.e. every single time you add an entry you associate a random number with it) then a good mechanism to use is the LFSR - Linear Feedback Shift Register. An n-bit LFSR will iterate through 2^n numbers in a fixed (deterministic) sequence (thus, not very random, but it might suit your purposes for uniqueness) and guarantees to loop back to the first number outputted after 2^n iterations. I'm a little rusty on the details, but it should definitely guarantee that you don't exhaust every number for a "long" time. Xilinx has a good app note on this: http://www.xilinx.com/support/documentation/application_notes/xapp052.pdf[^]