Prefer Futures to Baked-In "Async APIs"

Tools
  • Print
  • Email
When designing concurrent APIs, separate "what" from "how"

Herb Sutter is a bestselling author and consultant on software development topics, and a software architect at Microsoft. He can be contacted at www.gotw.ca.


Let's say you have an existing synchronous API function:


// Example 1: Original synchronous API
// that could take a long time to execute
// (to compute, to wait for disk/web, etc.)
//
RetType DoSomething(
  InParameters ins,
  OutParameters outs
);

Because DoSomething could take a long time to execute (whether it keeps a CPU core busy or not), and might be independent of other work the caller is doing, naturally the caller might want to execute DoSomething asynchronously. For example, consider calling code like this:


// Example 1, continued:
// Sample calling code
//
void CallerMethod() {
  // 

  result = DoSomething( this, that, outTheOther );

  // These could also take a long time
  OtherWork();
  MoreOtherWork();

  //  now use result and outOther 
}

If OtherWork and MoreOtherWork don't depend on the value of result or other side effects of DoSomething, and if they can correctly run concurrently with DoSomething because they don't conflict by using the same data or resources, then it could be useful to execute DoSomething concurrently with OtherWork/MoreOtherWork.

The question is, how should we enable that? There is a simple and correct answer, but because many interfaces have opted for a more complex answer let's consider that one first.

PAGE 1 | 2 | 3 Next Page »

Third International Workshop on Parallel Programming Models and Systems Software for High-End Computing

Parallel Architectures and Compilation Techniques
  • September 11-15, 2010
    The International Conference on Parallel Architectures and Compilation Techniques (PACT) is a premier international forum for the presentation of research results in parallel computing. As a multi-disciplinary conference that brings together researchers from the hardware and software areas, PACT brings together researchers and practitioners in parallel systems to present ground-breaking research related to parallel systems ranging across instruction-level parallelism, thread-level parallelism, multiprocessor parallelism and large scale systems.


IDF2010
  • September 13-15, 2010
    The Intel Developer Forum 2010 is your opportunity to collaborate with thousands of key industry players. Hear from more than 150 leading technology companies from around the world. Ask questions, get answers, experience live demonstrations, and more. Between the highly informative Keynotes, Technology and Industry Insights, Intel Fellows Live & Uncensored and Technical Sessions (including lectures, interactive panels, hands-on labs and Hot Topic Q&As), this year's IDF has everything you need to stay on top of the latest technology trends.
PPoPP
  • February 12-16, 2011
    The Symposium on Principles and Practice of Parallel Programming is a forum for leading work on all aspects of parallel programming, including foundational and theoretical aspects, techniques, tools, and practical experiences. In the context of the symposium, "parallel programming" encompasses work on concurrent and parallel systems (multicore, multithreaded, heterogeneous, clustered systems, distributed systems, and large scale machines). Given the rise of parallel architectures into the consumer market (desktops, laptops, and mobile devices), PPoPP is particularly interested in work that addresses new parallel workloads, techniques and tools that attempt to improve the productivity of parallel programming, and work towards improved synergy with such emerging architectures.