title: How can I require thread-safety of parameters in an interface?
body: <p>Suppose I have some interface that takes some set of numbers <code>foo</code> and performs some permutation <code>bar</code> on them:</p>
  
  <pre><code>class Interface
  {
  public:
    virtual std::vector&lt;double&gt; PerformBar(const std::vector&lt;double&gt;&amp; foo) = 0;
    virtual void SetBar(std::function&lt;double(double)&gt;&amp;&amp; func) = 0;
  };
  </code></pre>
  
  <p>If the implementation were single-threaded, there would be no issue, but what if my implementation attempts to parallelise its task?</p>
  
  <pre><code>class Impl final : public Interface
  {
  public:
    std::vector&lt;double&gt; PerformBar(const std::vector&lt;double&gt;&amp; foo) override
    {
      std::vector&lt;double&gt; result(foo.size());
      std::thread t1([&amp;]()
        {
          for (int i = 0; i != foo.size() / 2; ++i)
            result[i] = bar(foo[i]);
        });
  
      std::thread t2([&amp;]()
        {
          for (int i = foo.size() / 2; i != foo.size(); ++i)
            result[i] = bar(foo[i]);
        });
  
      t1.join();
      t2.join();
  
      return result;
    }
  
    void SetBar(std::function&lt;double(double)&gt;&amp;&amp; func) override
    {
      bar = func;
    }
  
  private:
    std::function&lt;double(double)&gt; bar;
  };
  </code></pre>
  
  <p>Currently, my interface does not make it clear to the user that <code>func</code> should be thread-safe, nor does it enforce that the implementation assume it is <em>not</em> thread safe.</p>
  
  <p>Other than adding comments, how can I modify my interface to ensure that the user understand that <code>func</code> must be thread-safe?</p>