Boost logo

Boost Users :

Subject: Re: [Boost-users] Is the following use of boost::function<> safe?
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2013-12-09 09:29:53


AMDG

On 12/09/2013 12:09 AM, David Goodenough wrote:
>
> namespace Thread
> {
> void ThreadRun(boost::function<void()> const &job);
> void ThreadDelayedRun(boost::function<void()> const &job, unsigned int
> delay);
> };
>
> <snip>
>
> int myFunc1(int a, int b)
> {
> ...
> return x
> }
> <snip>
> My only concern is the
> second case where I have myFunc1() whose return type is int, yet in the
> prototype for ThreadDelayedRun() I'm making it look a whole lot like it's
> void.
>

That isn't a problem at all. boost::function<void()> is
specified to discard any return value.

> The return type ultimately doesn't matter since this is specifically
> designed to be a "fire and forget" system, which means that any return
> value will be lost, there's no way for the invoking thread to recover it.
>

In Christ,
Steven Watanabe


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net