简体   繁体   中英

How can I return a value from a thread without using the future header?

My current compiler doesn't support the future header, and I'm unable to update it as on Android, the compiler is wrapped in an app. Because of this, I decided to try to make my own simple future class. I have most of it laid out, but can't figure out how to get the return value from the thread (as this seems to be beyond its intended use). I could pass my future class a functor that contains it's own return holder variable to be retrieved later, but that's a little limiting, because anything I wanted to pass it would have to be derived from the original functors class, and not just a function.

Is there any way to achieve this? I'm assuming the standard future header doesn't use black magic to do it. Does it use a "different version" of threads that allow it to receive a value back?

(It's not so old as to not be compatible with threading, it just has issues with the future header for some reason)

Thanks

I think by writing your own simple Future class you're on the right way. What does your code look like?

I'm not sure if I fully understand your statement:

I could pass my future class a functor that contains it's own return holder variable to be retrieved later, but that's a little limiting, because anything I wanted to pass it would have to be derived from the original functors class, and not just a function.

I wouldn't pass a functor but only store variables for the values I want as return values from the thread. If you want different return values you could derive classes from your SimpleFuture class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM