Spurious wakeups may sound strange, but on some multiprocessor systems, making condition wakeup completely predictable might substantially slow all condition variable operations.
intReadFunc(void* ptr, uint8_t* buf, int buf_size) { // Left to implement } int64_tSeekFunc(void* ptr, int64_t pos, int whence) { // Left to implement } AVIOContext* pIOCtx = avio_alloc_context(pBuffer, iBufSize, // internal Buffer and its size 0, // bWriteable (1=true,0=false) pContext, // user data ; will be passed to our callback functions ReadFunc, 0, // Write callback function (not used in this example) SeekFunc);
if (avformat_open_input(&pCtx, "", 0, 0)) != 0) // Error Handling
接著就跟一般無異了
Final
使用完後需要釋放資源
1 2 3
avformat_close_input(pCtx); // AVFormatContext is released by avformat_close_input av_free(pIOCtx); // AVIOContext is released by av_free delete[] pBuffer;
// this could be some long running computation or I/O future<int> calculate_the_answer() { return async([] { this_thread::sleep_for(1s); return42; }); }
// Here is a resumable function future<void> coro(){ cout << this_thread::get_id() << " Started waiting... \n"; auto result = await calculate_the_answer(); cout << this_thread::get_id() << " : woke up, get " << result << endl; }
intmain(int argc, char* argv[]) { coro().get(); cout << this_thread::get_id() << ": back in main\n"; }