multithreading - Parallel Synchronized Iterative Tasks in Native C++ -


I am using the original C ++ (no.net or / clr) and if so, The least dependence on external or third party libraries, which is where I got stuck.

To stay as close as possible to break my question, three work tasks 1 (), work 2 (), and task3 (). Each is part of a step in the repetition process, that is:

  while (true) {task1 (); task2 (); task3 (); }   

I'm looking for a way to execute task1 () and Task (3) in parallel. To recreate this, the following is the acceptable parallel:

Start - & gt; Work (1) - & gt; Work (2) - & gt; {Task3 () & amp; Work 1 () in parallel} - & gt; Work (2) - & gt; {Task3 () & amp; Work 1 () in parallel} - & gt; Work (2) - & gt; {Task3 () & amp; Work 1 () in parallel} - & gt; Work (2) - & gt; e.t.c.

Any help is appreciated, and like I said that I do not really want to be on any party party libraries and want to be in the original C ++ 11.

There can be a naïve approach in this way (only repeating part):

  while (true) {task2 (); Std :: Thread T1 (Task 1), T3 (Task 3); T1.join (); T3.join (); }   

This threshold may not be worth spinning every time or you may want to keep two threads alive and you can pass items that are working on them. This is actually a possible implementation for std :: async , although generally you do not have control over the entire code how async determines the time of its operation : while (true) {task2 (); Auto f1 = std :: async (task1), f3 (task3); f1.get (); F3.get (); }

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -