“睡眠”和“等待”有什么区别

what is difference between while(true) {sleep(1);} and while(true) {$queue.wait();}? which one will take the CPU cost?

i think the sleep execute will use CPU to calculate and compare the conditions; at the other side, wait is a blocking call, will not use CPU until something notify to wait it up

am i understood wrong? and how to implement wait in lower level? with sleep or other?

// example(in PHP):
while (true) {
    // do something 
    // until some conditions become true
    sleep(1);
}

while (true) {
    $data=$sock.accept(); // block until data response
    // $queue.wait(); // also block until data enqueue
    // do something
}

while(true) is basically while(true==true), which as you said, is an infinite loop!

Wait can be implemented using the sleep() function, yes.

while(condition=true)
{
sleep(x);
}

Where condition is what you are checking for (Page load, download finish, etc), and x is how long you want it to wait, in seconds.