문제

I have a vector<HANDLE>. I want to wait for all of them to finish. I don't want to copy them over to an array. What are the benefits of doing so anyway and using WaitForMultpleObjects, rather than using WaitForSingleObject in a loop if any?

Thanks!

도움이 되었습니까?

해결책

First, in every C++ compiler I know of, vectors are internally an array, and you can get a pointer to the array with &yourvector[0]. In C++11 I believe this behavior is also required by the standard. So there's no need to copy.

As for the benefit, WaitForMultipleObjects will reduce the number of times you wake up, saving some small amount of CPU time. It will also atomically acquire all of the HANDLEs at the same time - if you have a bunch of mutex or semaphore objects and need to lock them all, this can be important.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top