{"id":4767,"date":"2016-05-26T14:19:08","date_gmt":"2016-05-26T14:19:08","guid":{"rendered":"https:\/\/www.modernescpp.com\/index.php\/asynchronous-function-calls\/"},"modified":"2023-06-26T12:56:05","modified_gmt":"2023-06-26T12:56:05","slug":"asynchronous-function-calls","status":"publish","type":"post","link":"https:\/\/www.modernescpp.com\/index.php\/asynchronous-function-calls\/","title":{"rendered":"Asynchronous Function Calls"},"content":{"rendered":"<p><span style=\"font-family: courier new,courier;\">std:.async<\/span> feels like an asynchronous function call. Under the hood<span style=\"font-family: courier new,courier;\"> std::async<\/span> is a <a href=\"https:\/\/www.modernescpp.com\/index.php\/tasks\">task.<\/a> One, which is extremely easy to use.<\/p>\n<p><!--more--><\/p>\n<h2>std::async<\/h2>\n<p><span style=\"font-family: courier new,courier;\">std::async<\/span> gets a callable as a work package. In this example, it&#8217;s a function, a function object, or a lambda function.&nbsp;<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<table>\n<tbody>\n<tr>\n<td>\n<pre style=\"margin: 0; line-height: 125%;\"> 1\r\n 2\r\n 3\r\n 4\r\n 5\r\n 6\r\n 7\r\n 8\r\n 9\r\n10\r\n11\r\n12\r\n13\r\n14\r\n15\r\n16\r\n17\r\n18\r\n19\r\n20\r\n21\r\n22\r\n23\r\n24\r\n25\r\n26\r\n27\r\n28\r\n29\r\n30\r\n31\r\n32\r\n33\r\n34\r\n35\r\n36\r\n37\r\n38<\/pre>\n<\/td>\n<td>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008000;\">\/\/ async.cpp<\/span>\r\n\r\n<span style=\"color: #0000ff;\">#include &lt;future&gt;<\/span>\r\n<span style=\"color: #0000ff;\">#include &lt;iostream&gt;<\/span>\r\n<span style=\"color: #0000ff;\">#include &lt;string&gt;<\/span>\r\n\r\nstd::string helloFunction(<span style=\"color: #0000ff;\">const<\/span> std::string&amp; s){\r\n  <span style=\"color: #0000ff;\">return<\/span> <span style=\"color: #a31515;\">\"Hello C++11 from \"<\/span> + s + <span style=\"color: #a31515;\">\".\"<\/span>;\r\n}\r\n\r\n<span style=\"color: #0000ff;\">class<\/span> <span style=\"color: #2b91af;\">HelloFunctionObject<\/span>{\r\n  public:\r\n    std::string <span style=\"color: #0000ff;\">operator<\/span>()(<span style=\"color: #0000ff;\">const<\/span> std::string&amp; s) <span style=\"color: #0000ff;\">const<\/span> {\r\n      <span style=\"color: #0000ff;\">return<\/span> <span style=\"color: #a31515;\">\"Hello C++11 from \"<\/span> + s + <span style=\"color: #a31515;\">\".\"<\/span>;\r\n    }\r\n};\r\n\r\n<span style=\"color: #2b91af;\">int<\/span> main(){\r\n\r\n  std::cout &lt;&lt; std::endl;\r\n\r\n  <span style=\"color: #008000;\">\/\/ future with function<\/span>\r\n  <span style=\"color: #0000ff;\">auto<\/span> futureFunction= std::async(helloFunction,<span style=\"color: #a31515;\">\"function\"<\/span>);\r\n\r\n  <span style=\"color: #008000;\">\/\/ future with function object<\/span>\r\n  HelloFunctionObject helloFunctionObject;\r\n  <span style=\"color: #0000ff;\">auto<\/span> futureFunctionObject= std::async(helloFunctionObject,<span style=\"color: #a31515;\">\"function object\"<\/span>);\r\n\r\n  <span style=\"color: #008000;\">\/\/ future with lambda function<\/span>\r\n  <span style=\"color: #0000ff;\">auto<\/span> futureLambda= std::async([](<span style=\"color: #0000ff;\">const<\/span> std::string&amp; s ){<span style=\"color: #0000ff;\">return<\/span> <span style=\"color: #a31515;\">\"Hello C++11 from \"<\/span> + s + <span style=\"color: #a31515;\">\".\"<\/span>;},<span style=\"color: #a31515;\">\"lambda function\"<\/span>);\r\n\r\n  std::cout &lt;&lt; futureFunction.get() &lt;&lt; <span style=\"color: #a31515;\">\"\\n\"<\/span> \r\n\t    &lt;&lt; futureFunctionObject.get() &lt;&lt; <span style=\"color: #a31515;\">\"\\n\"<\/span> \r\n\t    &lt;&lt; futureLambda.get() &lt;&lt; std::endl;\r\n\r\n  std::cout &lt;&lt; std::endl;\r\n\r\n}\r\n<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>&nbsp;<\/p>\n<p>The program execution is not so exciting.<\/p>\n<p>&nbsp;<img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-4762\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/05\/async.png\" alt=\"async\" width=\"472\" height=\"205\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/05\/async.png 472w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/05\/async-300x130.png 300w\" sizes=\"auto, (max-width: 472px) 100vw, 472px\" \/><\/p>\n<p>The future gets a function (line 23), a function object (line 27), and a lambda function (line 30). In the end, each future requests its value (line 32).<\/p>\n<p>And again, a little bit more formal. The <span style=\"font-family: courier new,courier;\">std::async<\/span> calls in lines 23, 27, and 30 create a <a href=\"https:\/\/www.modernescpp.com\/index.php\/tasks\">data channel <\/a>between the two endpoints&#8217; future and promise. The promise immediately starts to execute its work package. But that is only the default behavior.&nbsp;By the get call, the future requests the result of Its work packages.<\/p>\n<\/p>\n<h2>Eager or lazy evaluation<\/h2>\n<p>Eager&nbsp;or lazy evaluation are two orthogonal strategies to calculate the result of an expression. In the case of <a href=\"https:\/\/en.wikipedia.org\/wiki\/Eager_evaluation\">eager evaluation<\/a>,&nbsp;the expression will immediately be evaluated; in the case of <a href=\"https:\/\/en.wikipedia.org\/wiki\/Lazy_evaluation\">lazy evaluation<\/a>, the expression will only be evaluated if needed. Often lazy evaluation is called call-by-need. With lazy evaluation, you save time and compute power because there is no evaluation on suspicion. An expression can be a mathematical calculation, a function, or a <span style=\"font-family: courier new,courier;\">std::async<\/span> call.&nbsp;<\/p>\n<p>By default, std::async executed its work package immediately. The C++ runtime decides if the calculation happens in the same or a new thread. With the flag <span style=\"font-family: courier new,courier;\">std::launch::async<\/span> <span style=\"font-family: courier new,courier;\">std::async<\/span> will run its work package in a new thread. In opposition to that,&nbsp;the flag std::launch::deferred expresses that std::async runs in the same thread. The execution is, in this case, lazy. That implies that the eager evaluations start immediately, but the lazy evaluation with the policy <span style=\"font-family: courier new,courier;\">std::launch::deferred<\/span> starts when the future asks for the value with its get call.&nbsp;<\/p>\n<p>The program shows different behavior.<br \/><span style=\"font-family: courier new,courier;\"><span style=\"font-family: courier new,courier;\"><span style=\"font-family: arial,helvetica,sans-serif;\"><\/span><\/span><span style=\"font-family: arial,helvetica,sans-serif;\"> <\/span> <\/span><\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<table>\n<tbody>\n<tr>\n<td>\n<pre style=\"margin: 0; line-height: 125%;\"> 1\r\n 2\r\n 3\r\n 4\r\n 5\r\n 6\r\n 7\r\n 8\r\n 9\r\n10\r\n11\r\n12\r\n13\r\n14\r\n15\r\n16\r\n17\r\n18\r\n19\r\n20\r\n21\r\n22\r\n23\r\n24\r\n25\r\n26\r\n27\r\n28\r\n29\r\n30<\/pre>\n<\/td>\n<td>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008000;\">\/\/ asyncLazy.cpp<\/span>\r\n\r\n<span style=\"color: #0000ff;\">#include &lt;chrono&gt;<\/span>\r\n<span style=\"color: #0000ff;\">#include &lt;future&gt;<\/span>\r\n<span style=\"color: #0000ff;\">#include &lt;iostream&gt;<\/span>\r\n\r\n<span style=\"color: #2b91af;\">int<\/span> main(){\r\n\r\n  std::cout &lt;&lt; std::endl;\r\n\r\n  <span style=\"color: #0000ff;\">auto<\/span> begin= std::chrono::system_clock::now();\r\n\r\n  <span style=\"color: #0000ff;\">auto<\/span> asyncLazy=std::async(std::launch::deferred,[]{ <span style=\"color: #0000ff;\">return<\/span>  std::chrono::system_clock::now();});\r\n\r\n  <span style=\"color: #0000ff;\">auto<\/span> asyncEager=std::async( std::launch::async,[]{ <span style=\"color: #0000ff;\">return<\/span>  std::chrono::system_clock::now();});\r\n\r\n  std::this_thread::sleep_for(std::chrono::seconds(1));\r\n\r\n  <span style=\"color: #0000ff;\">auto<\/span> lazyStart= asyncLazy.get() - begin;\r\n  <span style=\"color: #0000ff;\">auto<\/span> eagerStart= asyncEager.get() - begin;\r\n\r\n  <span style=\"color: #0000ff;\">auto<\/span> lazyDuration= std::chrono::duration&lt;<span style=\"color: #2b91af;\">double<\/span>&gt;(lazyStart).count();\r\n  <span style=\"color: #0000ff;\">auto<\/span> eagerDuration=  std::chrono::duration&lt;<span style=\"color: #2b91af;\">double<\/span>&gt;(eagerStart).count();\r\n\r\n  std::cout &lt;&lt; <span style=\"color: #a31515;\">\"asyncLazy evaluated after : \"<\/span> &lt;&lt; lazyDuration &lt;&lt; <span style=\"color: #a31515;\">\" seconds.\"<\/span> &lt;&lt; std::endl;\r\n  std::cout &lt;&lt; <span style=\"color: #a31515;\">\"asyncEager evaluated after: \"<\/span> &lt;&lt; eagerDuration &lt;&lt; <span style=\"color: #a31515;\">\" seconds.\"<\/span> &lt;&lt; std::endl;\r\n\r\n  std::cout &lt;&lt; std::endl;\r\n\r\n}\r\n<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>&nbsp;<\/p>\n<p>Both <span style=\"font-family: courier new,courier;\">std::async<\/span> calls (lines 13 and 15) return the current time point. But the first call is lazy, the second greedy. The short sleep of one second in line 17 makes that obvious. By the call <span style=\"font-family: courier new,courier;\">asyncLazy.get()<\/span> in line 19, the result will be available after a short nap.&nbsp; This is not true for<span style=\"font-family: courier new,courier;\"> asyncEager. asyncEager.get()<\/span> gets the result from the immediately executed work package.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-4763\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/05\/asyncLazy.png\" alt=\"asyncLazy\" width=\"472\" height=\"195\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/05\/asyncLazy.png 472w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/05\/asyncLazy-300x124.png 300w\" sizes=\"auto, (max-width: 472px) 100vw, 472px\" \/><\/p>\n<h2>A bigger computing job<\/h2>\n<p><span style=\"font-family: courier new,courier;\">std::async<\/span> is quite convenient to put a bigger compute job on more shoulders. So, the scalar product is calculated in the program with four asynchronous function calls.<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<table>\n<tbody>\n<tr>\n<td>\n<pre style=\"margin: 0; line-height: 125%;\"> 1\r\n 2\r\n 3\r\n 4\r\n 5\r\n 6\r\n 7\r\n 8\r\n 9\r\n10\r\n11\r\n12\r\n13\r\n14\r\n15\r\n16\r\n17\r\n18\r\n19\r\n20\r\n21\r\n22\r\n23\r\n24\r\n25\r\n26\r\n27\r\n28\r\n29\r\n30\r\n31\r\n32\r\n33\r\n34\r\n35\r\n36\r\n37\r\n38\r\n39\r\n40\r\n41\r\n42\r\n43\r\n44\r\n45\r\n46\r\n47\r\n48\r\n49\r\n50\r\n51\r\n52\r\n53<\/pre>\n<\/td>\n<td>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008000;\">\/\/ dotProductAsync.cpp<\/span>\r\n\r\n<span style=\"color: #0000ff;\">#include &lt;chrono&gt;<\/span>\r\n<span style=\"color: #0000ff;\">#include &lt;iostream&gt;<\/span>\r\n<span style=\"color: #0000ff;\">#include &lt;future&gt;<\/span>\r\n<span style=\"color: #0000ff;\">#include &lt;random&gt;<\/span>\r\n<span style=\"color: #0000ff;\">#include &lt;vector&gt;<\/span>\r\n<span style=\"color: #0000ff;\">#include &lt;numeric&gt;<\/span>\r\n\r\n<span style=\"color: #0000ff;\">static<\/span> <span style=\"color: #0000ff;\">const<\/span> <span style=\"color: #2b91af;\">int<\/span> NUM= 100000000;\r\n\r\n<span style=\"color: #2b91af;\">long<\/span> <span style=\"color: #2b91af;\">long<\/span> getDotProduct(std::vector&lt;<span style=\"color: #2b91af;\">int<\/span>&gt;&amp; v, std::vector&lt;<span style=\"color: #2b91af;\">int<\/span>&gt;&amp; w){\r\n\r\n  <span style=\"color: #0000ff;\">auto<\/span> future1= std::async([&amp;]{<span style=\"color: #0000ff;\">return<\/span> std::inner_product(&amp;v[0],&amp;v[v.size()\/4],&amp;w[0],0LL);});\r\n  <span style=\"color: #0000ff;\">auto<\/span> future2= std::async([&amp;]{<span style=\"color: #0000ff;\">return<\/span> std::inner_product(&amp;v[v.size()\/4],&amp;v[v.size()\/2],&amp;w[v.size()\/4],0LL);});\r\n  <span style=\"color: #0000ff;\">auto<\/span> future3= std::async([&amp;]{<span style=\"color: #0000ff;\">return<\/span> std::inner_product(&amp;v[v.size()\/2],&amp;v[v.size()*3\/4],&amp;w[v.size()\/2],0LL);});\r\n  <span style=\"color: #0000ff;\">auto<\/span> future4= std::async([&amp;]{<span style=\"color: #0000ff;\">return<\/span> std::inner_product(&amp;v[v.size()*3\/4],&amp;v[v.size()],&amp;w[v.size()*3\/4],0LL);});\r\n\r\n  <span style=\"color: #0000ff;\">return<\/span> future1.get() + future2.get() + future3.get() + future4.get();\r\n}\r\n\r\n\r\n<span style=\"color: #2b91af;\">int<\/span> main(){\r\n\r\n  std::cout &lt;&lt; std::endl;\r\n\r\n  <span style=\"color: #008000;\">\/\/ get NUM random numbers from 0 .. 100<\/span>\r\n  std::random_device seed;\r\n\r\n  <span style=\"color: #008000;\">\/\/ generator<\/span>\r\n  std::mt19937 engine(seed());\r\n\r\n  <span style=\"color: #008000;\">\/\/ distribution<\/span>\r\n  std::uniform_int_distribution&lt;<span style=\"color: #2b91af;\">int<\/span>&gt; dist(0,100);\r\n\r\n  <span style=\"color: #008000;\">\/\/ fill the vectors<\/span>\r\n  std::vector&lt;<span style=\"color: #2b91af;\">int<\/span>&gt; v, w;\r\n  v.reserve(NUM);\r\n  w.reserve(NUM);\r\n  <span style=\"color: #0000ff;\">for<\/span> (<span style=\"color: #2b91af;\">int<\/span> i=0; i&lt; NUM; ++i){\r\n    v.push_back(dist(engine));\r\n    w.push_back(dist(engine));\r\n  }\r\n\r\n  <span style=\"color: #008000;\">\/\/ measure the execution time<\/span>\r\n  std::chrono::system_clock::time_point start = std::chrono::system_clock::now();\r\n  std::cout &lt;&lt; <span style=\"color: #a31515;\">\"getDotProduct(v,w): \"<\/span> &lt;&lt; getDotProduct(v,w) &lt;&lt; std::endl;\r\n  std::chrono::duration&lt;<span style=\"color: #2b91af;\">double<\/span>&gt; dur  = std::chrono::system_clock::now() - start;\r\n  std::cout &lt;&lt; <span style=\"color: #a31515;\">\"Parallel Execution: \"<\/span>&lt;&lt; dur.count() &lt;&lt; std::endl;\r\n\r\n  std::cout &lt;&lt; std::endl;\r\n\r\n}\r\n<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>&nbsp;<\/p>\n<p>The program uses the functionality of the random and time library. Both libraries are part of C++11. The vectors v and w are created and filled with a random number in lines 27 &#8211; 43.&nbsp; Each vector gets (lines 40 &#8211; 43) a hundred million elements. <span style=\"font-family: courier new,courier;\">dist(engine)<\/span> in lines 41 and 42 generated random numbers uniformly distributed from 0 to 100. The current calculation of the scalar product takes place in the function<span style=\"font-family: courier new,courier;\"> getDotProduct<\/span> (lines 12 &#8211; 20). <span style=\"font-family: courier new,courier;\">std::async<\/span> uses the standard template library algorithm std::inner_product internally<span style=\"font-family: courier new,courier;\">. <\/span>The return statement sums up the results of the futures.<\/p>\n<p>It takes&nbsp;about 0.4 seconds to calculate the result on my PC.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-4764\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/05\/dotProductAsync.png\" alt=\"dotProductAsync\" width=\"472\" height=\"195\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/05\/dotProductAsync.png 472w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/05\/dotProductAsync-300x124.png 300w\" sizes=\"auto, (max-width: 472px) 100vw, 472px\" \/><\/p>\n<p>But now the question is. How fast is the program if I executed it on one core? A slight modification of the function <span style=\"font-family: courier new,courier;\">getDotProduct<\/span>, and we know the truth.<\/p>\n<div style=\"background: #ffffff none repeat scroll 0% 0%; overflow: auto; width: auto; border-width: 0.1em 0.1em 0.1em 0.8em;\">\n<pre style=\"margin: 0px; line-height: 125%;\"><span style=\"color: #2b91af;\"><br \/>long<\/span> <span style=\"color: #2b91af;\">long<\/span> getDotProduct(std::vector&lt;<span style=\"color: #2b91af;\">int<\/span>&gt;&amp; v,std::vector&lt;<span style=\"color: #2b91af;\">int<\/span>&gt;&amp; w){\r\n  <span style=\"color: #0000ff;\">return<\/span> std::inner_product(v.begin(),v.end(),w.begin(),0LL);\r\n}\r\n<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>The execution of the program is four times slower.<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-4765\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/05\/dotProduct.png\" alt=\"dotProduct\" width=\"647\" height=\"199\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/05\/dotProduct.png 647w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/05\/dotProduct-300x92.png 300w\" sizes=\"auto, (max-width: 647px) 100vw, 647px\" \/><\/p>\n<h3>Optimization<\/h3>\n<p>But, if I compile the program with maximal optimization level O3 with my GCC, the performance difference is nearly gone. The parallel execution is about 10 percent faster.<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-4766\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/05\/dotProductComparisonOptimization.png\" alt=\"dotProductComparisonOptimization\" width=\"647\" height=\"280\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/05\/dotProductComparisonOptimization.png 647w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/05\/dotProductComparisonOptimization-300x130.png 300w\" sizes=\"auto, (max-width: 647px) 100vw, 647px\" \/><\/p>\n<h2>What&#8217;s next?<\/h2>\n<p>In the<a href=\"https:\/\/www.modernescpp.com\/index.php\/asynchronous-callable-wrappers\"> next post, <\/a>I will show you how to parallelize a big compute job by using <span style=\"font-family: courier new,courier;\">std::packaged_task. (<strong>Proofreader Alexey <\/strong><strong>Elymanov<\/strong>)<\/span><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>std:.async feels like an asynchronous function call. Under the hood std::async is a task. One, which is extremely easy to use.<\/p>\n","protected":false},"author":21,"featured_media":4762,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[366],"tags":[524,446],"class_list":["post-4767","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-multithreading","tag-async","tag-tasks"],"_links":{"self":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/4767","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/users\/21"}],"replies":[{"embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/comments?post=4767"}],"version-history":[{"count":1,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/4767\/revisions"}],"predecessor-version":[{"id":6977,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/4767\/revisions\/6977"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/media\/4762"}],"wp:attachment":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/media?parent=4767"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/categories?post=4767"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/tags?post=4767"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}