virThread: why no return values permitted in thread API?

Michal Prívozník mprivozn at redhat.com
Wed Apr 20 12:51:54 UTC 2022


On 4/20/22 14:24, 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.
> 
> 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?
> 
> Should I use pthread directly instead?

Not at all. Just change the type of virThreadJoin(). At which point it's
harder to distinguish whether thread ran and returned a value, or thread
did not run/exited before the callback was called and retval we are
seeing comes from virThreadHelper(), but since it does not return
anything yet, it's easy to distinguish the two.

Whatever you do, please avoid using pthread directly.

Michal



More information about the libvir-list mailing list