[Interest] is it ok to push audio on a background thread, not a timer?

Thiago Macieira thiago.macieira at intel.com
Tue May 19 03:19:10 CEST 2020


On Monday, 18 May 2020 17:42:10 PDT David M. Cotter wrote:
> > Like every QObject class, unless noted otherwise, you may not call methods
> > on the object from outside the object's thread of affinity (the one it
> > was created in or moved to with moveToThread). Your code is abusing the
> > API in both cases if you're using the API from another thread.
> 
> To be clear: I'm not  initting any Qt objects in the constructor, that all 
> happens inside the run() function, in the i_auP->Start(&i_outP); call.

That's not clear from your code:
    QAudioOutput	*audioOutput(auP->i_qGeneratorP->i_qOutputP.get());

The CAudioUnit class is not defined anywhere in your code.

> Specifically: both i_qGeneratorP and i_qOutputP are allocated there. I think
> they're the only Qt objects use within the new thread?

If you say so, but I can't confirm that you've done the right thing since I 
can't see those classes. Note that you do initialise the i_auP pointer in your 
constructor's initialisation list:
		i_auP(in_thiz->GetCUnit_Out())

You call this GetCUnit_Out() function in both threads. I can't tell what this 
function is doing, I don't know what i_qGeneratorP is and what thread its 
i_qOutputP pointer is filled in.

Please make a small, self-contained and compileable example of the problem.

> Is there some other object you think is being cross-thread abused?
> 
> You mention "both cases", what cases are you referring to?

Mac and Windows.

PS: if you're using Hungarian notation, doesn't the "i" prefix indicate 
"integer"? Why are you using it for pointers?

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel System Software Products





More information about the Interest mailing list