c++ - Making one of the threads to wait for least possible (almost zero) time -


A list is working on two types of threads (exclusive use of STL containers to be listed as threads after).

  • Adder thread: The item is being added to the list by several sources. / P>

  • Processor thread: A thread

< / P>

>

Problem: When the processor wants access to the thread list, it should be quick access (even if the other addendum thread is already waiting to reach the list , The processor thread should be given top priority). Ideally I'm not expecting almost any wait.

  1. Will thread priority be helped to solve it?
  2. Is there an algorithmic solution (alternative ways can be etc.)?

(The way the solution can be specific even for the Windows operating system, if this solves the problem)

I had not yet opened in the thread, but what about using two mutes for it? A adder_queue mutex and a mute x access .

In the Adder Code

  std :: lock_guard & lt; Std :: mutex & gt; Queue_lock (adder_queue); Std :: lock_guard & lt; Std :: mutex & gt; Access_lock (access); // add operation  

and the processor can display threads

  std :: lock_guard & lt; Std :: mutex & gt; Access_lock (access); // Process Operation  

Adder threads should now wait for adder_queue mutex before locking access and thus processor thread Always need to be present after the ongoing operation


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -