views:

88

answers:

2

Like blocks until the file is done playing, what's the principle and how to implement this?

+1  A: 

"blocking" means that the operation will not return control to its caller until whatever it's "blocking until" is true.

This can be implemented in several ways:

  • Delegate the responsibility for blocking to someone else. For example, call pthread_mutex_lock, which may block. This makes your function block too. Other functions doing this are read and any other system call which says it may block.
  • Spin. In other words, have some code that looks like while (!condition) {}. This will eat an entire CPU core, so it's not a good practice if you're going to be blocking for any significant amount of time.
  • Use a signal handler. Call sleep(5000) or some such, and terminate the sleep via SIGALARM or another asynchronous method.

In the case of a media player, "blocking until the file is done playing" just means "waits until the media file is done playing before returning".

Borealid
In my case it's `pEvent->WaitForCompletion(INFINITE, `,do know how it's implemented?
Alan
Do you care on how it is implemented? You are using a method from an interface, and the interface documents the behavior. How that behavior is achieved (at this level) is probably much less important than what it does. You just need to know that whenever you call that method, the method will not return until the operation has completed: the execution flow is *blocked* until the condition is fulfilled.
David Rodríguez - dribeas
A: 

let a thread wait for an event which will be fired by another thread when file is done playing.

xqterry