symbian创建的新线程是否不能建c类对象?急~~!

zzg4321 2008-01-25 12:21:47
我在exe的工程中 创建的新线程,在线程中在创建新C类的时候会报错误,是不是不能创建此类对象呢,
如果可以应该如何创建,好像跟调度器是不是有关系阿?
...全文
141 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
bluepac 2008-05-07
  • 打赏
  • 举报
回复

void DoTheThingsForMeL(CConsoleBase* aConsole)
{
//Do something here.
}
void DoExampleL()
{
CConsoleBase* console;
// Make the console and push it on the cleanup stack.
console = Console::NewL(_L("Console"), TSize( KConsFullScreen, KConsFullScreen));
CleanupStack::PushL(console);
DoTheThingsForMeL(console);
CleanupStack::PopAndDestroy(console);
}

TInt E32Main()
{
__UHEAP_MARK;
//Create a cleanup stack
CTrapCleanup* cleanup = CTrapCleanup::New();
//Call some Leaving methods inside TRAP
TRAPD(error, DoExampleL());
__ASSERT_ALWAYS(!error, User::Panic(KAPConsoleTest, error));
//Destroy cleanup stack
delete cleanup;
__UHEAP_MARKEND;
return 0;
}

zzg4321 代码中ThreadFun 函数为什么又创建一个CTrapCleanup 对象? E32Main 一次创建应该就OK了把
hanxiao_0210 2008-01-30
  • 打赏
  • 举报
回复
mark
dyw 2008-01-25
  • 打赏
  • 举报
回复
Resume应只在线程刚创建或被Suspend之后调用。线程重启应重新创建,至于Panic应在交付使用前解决掉。
anel 2008-01-25
  • 打赏
  • 举报
回复
http://wiki.forum.nokia.com/index.php/How_to_create_a_simple_Thread.
zzg4321 2008-01-25
  • 打赏
  • 举报
回复
假如我创建的线程他出现PANIC的时候, 我想重新启动它,
id 为获取到的该线程ID

我用thread.Open(id);
thread.Resume();

是不是用这个重新 启动呢,但是似乎不能让它重新跑起来一样,怪~~!
dyw 2008-01-25
  • 打赏
  • 举报
回复
基本正确,实际上就是E32Main所做的工作。把E32Main稍微改造即可变为自己的线程入口函数。
zzg4321 2008-01-25
  • 打赏
  • 举报
回复
这样应该没有bug 吧?
zzg4321 2008-01-25
  • 打赏
  • 举报
回复
程序有BUG?晕,
我现在这样做了,似乎没有错误了,

GLDEF_C TInt E32Main()
{
__UHEAP_MARK;
CTrapCleanup* cleanup = CTrapCleanup::New(); // get clean-up stack
TRAPD(error, mainFun());
__ASSERT_ALWAYS(!error, User::Panic(KPROCESSNAME, error));
delete cleanup; // destroy clean-up stack
__UHEAP_MARKEND;

return 0;
}

void mainFun()
{
CActiveScheduler* scheduler = new(ELeave) CActiveScheduler();
CleanupStack::PushL(scheduler);
CActiveScheduler::Install(scheduler);
.......

User::LeaveIfError(thread.Create(_L("Thread"), ThreadFun, KDefaultStackSize, NULL, NULL));
thread.Resume();
CActiveScheduler::Start();

}

TInt ThreadFun()
{
/*----------------------------------------------------*/
__UHEAP_MARK;
CTrapCleanup* cleanup = CTrapCleanup::New(); // get clean-up stack

//创建线程调度器
CActiveScheduler* schedulerThread = new(ELeave) CActiveScheduler();
if ( NULL == schedulerThread )
{
return KErrNoMemory;
}
CActiveScheduler::Install(schedulerThread);
//增加以上代码就可以在自己的线程忠创建C类了,
......
}
anel 2008-01-25
  • 打赏
  • 举报
回复
程序有bug
dyw 2008-01-25
  • 打赏
  • 举报
回复
可以创建。需要创建TrapCleanup环境,参考:
	__UHEAP_MARK;
CTrapCleanup* cleanup=CTrapCleanup::New(); // get clean-up stack
TRAPD(error,YourWorkHereL()); // more initialization
__ASSERT_ALWAYS(!error,User::Panic(KTxtEPOC32EX,error));
delete cleanup; // destroy clean-up stack
__UHEAP_MARKEND;

3,119

社区成员

发帖
与我相关
我的任务
社区描述
塞班系统(Symbian系统)是塞班公司为手机而设计的操作系统,它的前身是英国宝意昂公司的 EP ( Electronic Piece of cheese)操作系统。
社区管理员
  • Symbian社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧