virThread: why no return values permitted in thread API?

Peter Krempa pkrempa at redhat.com
Wed Apr 20 12:33:19 UTC 2022


On Wed, Apr 20, 2022 at 14:24:39 +0200, Claudio Fontana wrote:
> Hi,
> 
> I noticed that in the virThread API return values from threads are explicitly excluded from the API.
> 
> The "virThreadHelper" sits in the middle between the caller of virThreadCreate and pthread, making it impossible to return a value from the thread,
> to check after joining the thread.

virThreadCreate has an 'opaque' parameter which allows to pass arbitrary
data to the trhead. You can use it to pass also data back, just apply
thread safety rules.

> I'd need to know if the thread execution is successful or not then I join the thread,
> so what is the reason for this choice?

Could you elaborate what you are trying to achieve?

> Should I use pthread directly instead?

Generally no, please use the internal helpers for code consistency.


More information about the libvir-list mailing list