Returning a value from thread?

前端 未结 17 2525
不思量自难忘°
不思量自难忘° 2020-11-27 09:45

How do I return a value from a thread?

17条回答
  •  囚心锁ツ
    2020-11-27 10:30

    A thread isn't a method - you don't normally "return" a value.

    However, if you're trying to fetch a value back from the results of some processing, you have many options, the two main ones being:

    • You can synchronize a shared piece of data, and set it appropriately.
    • You can also pass the data back in some form of callback.

    It really depends on how you're creating the thread, and how you want to use it, as well as the language/framework/tools you're using.

提交回复
热议问题