multithreading - What are some good use cases for calling 'yield' in a thread? -
Many languages that support multi-threading provide an action to present a thread to the reference switch in other threads allows for. Haskell for example.
However, the documentation does not tell what the real use cases are. Is it worthwhile to use these yield tasks, and when not?
Recently I have seen such an experiment where it has been found that when a network server sends a message, before trying to get the data yield
is worth calling, because the customer takes some time to answer and issue another request.
Yield
when you call, like other examples or guides.
I am mainly interested in Haskell, but I have no problem learning about other languages or concepts in general.
Note: It is not used with generator or cortinin, such as yield
in Python or Ruby.
The use of GHC's IO Manager to improve the performance yield < / Code> does. Can be found on use but I will paste it here as well.
step :: EventManager - & gt; IO State Stage @ Event Manager {..} = WaiterForio State & lt; - readIORef emState state `seq` return status where wait = n1 & lt; - I.poll embackend Nothing (onFdEvent MGR) when generated (N1 = 1 = $) = $ N2 and Lieutenant; - I.poll emBackend Nothing (onFdEvent MGR) when (n2 = 0 = $) $ & lt; - I.poll emBackend (bus forever) (onFdEvent mgr) return < The use of the [first non-blocking] voting fails to find the events, we give yields the election loop thread at the end of the Haskel run queue when it comes back, we have another non-blocking If we get lucky and ready, if he does not even give an event, then we do a blocking poll. Then yield
is used to reduce the number of blocking elections, EventManager
will be done.
Comments
Post a Comment