Is there a std :: future spin-wait?

Before explaining the question in more detail, I want to note that the answer clearly depends on the implementation, so I primarily ask about libstdC ++, but I will also be interested to know about libC ++. The operating system is Linux.

Call wait()or get()in blocks std::futureas long as the result will not be set asynchronous operation - or function std::promise, std::packaged_taskeither std::asyn. The availability of the result is conveyed through the general state, which is basically an atomic variable: the future expects the general state to be marked as ready by promise (or asynchronous task). This wait and notification is implemented in libstdC ++ using the futex system call. Suppose futexes are highly efficient, in situations where the future only expects to wait for a very short period (of the order of one microsecond), it would seem that performance gains can be achieved by rotating in general condition for a short time before continuing to wait for futex.

I did not find any evidence of such a rotation in the current implementation, however I found a comment in atomic_futex.h on line 161 where I expect to find such a rotation:

// TODO Spin-wait first.

So, my question is rather the following: are there really plans for introducing a spin-wait, and if so, how will the duration be determined? Also, is it a type of functionality that can ultimately be defined with the help of policies in the future?

+4
source share
1 answer

I will answer the question: does the std::future::get()queue wait?

++: . ( std::mutex::lock() ). , ? std::experimental::future ( ), boost::future ( , ), hpx::future ( future). , , , CPP. , - get_with_spins .

libstdc++ ( libc++): . TODO, , , - . GCC , . ( get() , ), .

: , , , , .

+3

Source: https://habr.com/ru/post/1668309/


All Articles