What is the difference between blocked and busy waiting?

I knew the implementation of Busy Waiting. this is a death cycle like this:

//main thread
while (true) {
    msg = msgQueue.next();
    msg.runnable.run();
}

//....msg queue
public Message next() {
    while (true) {
        if (!queue.isEmpty()) {
            return queue.dequeue();
        }
    }
}

therefore, the "next ()" method just looks blocked, in fact, it works all the time. this was called "waiting" in the book.

and what is the "process blocked"? how are things with its implementation? too the outline of death? or some others? how is the signal mechanism?

For example: cat xxx | grep "abc"

the "cat" process reads the file and displays it.

handle grep, waiting for input from cat.

"cat" "grep" , . "", ? , , ?

+6
2

, :

1.

, , , : " ? ? , ?" 100% :

bool are_we_there = false;
while(!are_we_there)
{
   // ask if we're there (without blocking)
    are_we_there = ask_if_we_are_there();
}

2. , ( )

, , , , , . .

- , - :

// use a system call to create a waitable timer
var timer = CreateWaitableTime()

// use another system call that waits on a waitable object
WaitFor(timer);  // this will block the current thread until the timer is signaled

// .. some time in the future, the timer might expire and it object will be signaled
//    causing the WaitFor(timer) call to resume operation

UPDATE

- , , , , , . , , , , , , , , , ( ). , , .

+9

" ", " ", , . , . , , , . , , . :

100:    if (data_available()) {
101:        return;
102:    } else {
103:        jump_to_scheduler();
104:    }

100, else . , .

, , , , .

0

All Articles