Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. create_task with asynchronous unwrapping PPL

create_task with asynchronous unwrapping PPL

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Daniel Ramnath
    wrote on last edited by
    #1

    I have a code as below.

    // async-unwrapping.cpp
    // compile with: /EHsc
    #include
    #include

    using namespace concurrency;
    using namespace std;

    int wmain()
    {
    auto t = create_task([]()
    {
    wcout << L"Task A" << endl;

        // Create an inner task that runs before any continuation
        // of the outer task.
        return create\_task(\[\]()
        {
            wcout << L"Task B" << endl;
        });
    });
    
    // Run and wait for a continuation of the outer task.
    t.then(\[\](task& t3) // or task t3
    {
        wcout << L"Task C" << endl;
        t3.wait(); // or .get()
    }).wait();
    

    }

    I expected the output to be /* Output: Task A Task B Task C Task B */ But the output is /* Output: Task A Task B Task C */ Why t3.wait(); isn't calling the B task again or a tleast should throw error?

    Jesus saves

    L 1 Reply Last reply
    0
    • D Daniel Ramnath

      I have a code as below.

      // async-unwrapping.cpp
      // compile with: /EHsc
      #include
      #include

      using namespace concurrency;
      using namespace std;

      int wmain()
      {
      auto t = create_task([]()
      {
      wcout << L"Task A" << endl;

          // Create an inner task that runs before any continuation
          // of the outer task.
          return create\_task(\[\]()
          {
              wcout << L"Task B" << endl;
          });
      });
      
      // Run and wait for a continuation of the outer task.
      t.then(\[\](task& t3) // or task t3
      {
          wcout << L"Task C" << endl;
          t3.wait(); // or .get()
      }).wait();
      

      }

      I expected the output to be /* Output: Task A Task B Task C Task B */ But the output is /* Output: Task A Task B Task C */ Why t3.wait(); isn't calling the B task again or a tleast should throw error?

      Jesus saves

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      That's the thing with parallelism, it never does what you expect.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups