Symbian C++ : About RThread?

I read pcm data from file and then write to outputstream, it's ok. But when I create another thread to read pcm data and then write to outputstream, it has an exception and haven't any sound. Why?

It's like:

class CSpeechEngine : public CBase, public MMdaAudioOutputStreamCallback
{
...
void PlayL(TUint8* aData, TUint32 dataLen);
TPtr8 iDescBuf;
CMdaAudioOutputStream* iStream;
...
};
// 写数据到输出流
void CSpeechEngine::PlayL(TUint8* aData, TUint32 dataLen)
{
if( EEngineReady == iStatus )
{
iStatus = EEnginePlaying;
iDescBuf.Set(aData, dataLen, dataLen);
iStream->WriteL(iDescBuf);
}
}

//TestThreadAppUi.cpp
_LIT(KPCMFilename1, "sample1.pcm");
RSemaphore _sp_newData;
void CTestThreadAppUi::ConstructL()
{
sp = CSpeechEngine::NewL();
_sp_newData.CreateLocal(0);
}

const TUint KDefaultHeapSize=0x80000;
const TUint KStackSize = 0x40000;
struct CFileHeader
{
TInt iFileSize;
TUint8* pPCMBuffer;
};
TBool LoadFile(const TDesC& aFileName, CFileHeader* pFileHeader)
{
TBool nRet = EFalse;
TInt iFileSize = 0;
TUint8* iPCMBuffer = NULL;
TPtr8 iDescBuf(0, 0);

RFs fs;
RFile file;
TInt fileErr = 0;

// CleanupClosePushL(fs);
User::LeaveIfError(fs.Connect());

// CleanupClosePushL(file);
fileErr = file.Open(fs, aFileName, EFileRead|EFileShareReadersOnly);

if( KErrNone == fileErr )
{
file.Size( iFileSize );
iPCMBuffer = new (ELeave) TUint8[iFileSize];
iDescBuf.Set(iPCMBuffer, iFileSize, iFileSize);
file.Read( iDescBuf );

pFileHeader->iFileSize = iFileSize;
pFileHeader->pPCMBuffer = iPCMBuffer;
nRet = ETrue;
}

file.Close();
fs.Close();
// CleanupStack::PopAndDestroy(2);
return nRet;
}
TInt CTestThreadAppUi::ThreadFunction(TAny* anArg)
{
CFileHeader* pFH = (CFileHeader*)anArg;
LoadFile(KPCMFilename1, pFH); // read pcm data from file
_sp_newData.Signal();
return 0;

}
void CTestThreadAppUi::HandleCommandL(TInt aCommand)
{
static CFileHeader fh;

switch ( aCommand )
{
case EAknSoftkeyBack:
case EEikCmdExit:
{
delete fh.pPCMBuffer;
Exit();
break;
}
case ETestThreadCmdAppTest:
{
iEikonEnv->InfoMsg(_L("test"));
RThread rdThread;
_LIT(KReadDataThread,"ReadDataThread");
TInt res = rdThread.Create( KReadDataThread, // create new server thread
ThreadFunction, // thread's main function
KStackSize,
KMinHeapSize,
KDefaultHeapSize,
(TAny*)&fh
);
if( res == KErrNone )
{
rdThread.SetPriority(EPriorityNormal);
rdThread.Resume();
_sp_newData.Wait();
}
sp->PlayL(fh.pPCMBuffer, fh.iFileSize);
break;
}
// TODO: Add Your command handling code here

default:
break;
}
}

Please help me! Thank you!
If need the source code, please to me: xjhong@iflytek.com
[3300 byte] By [window8297] at [2008-5-23]
# 1
线程不一样的吆。
ljhcy-ljhcy at 2007-10-22 > top of Msdn China Tech,移动平台,手机操作系统...
# 2
那问题出现在哪儿呢?请帮帮忙,谢谢!
window8297 at 2007-10-22 > top of Msdn China Tech,移动平台,手机操作系统...
# 3
你去看看线程地堆栈,你就会明白一点。
ljhcy-ljhcy at 2007-10-22 > top of Msdn China Tech,移动平台,手机操作系统...