所以我下载了flascc,并摆弄了一下样例。
示例09 (线程)和示例12 ( Stage3D )本身工作得很好,但当我尝试在Stage3D示例中运行线程时,它们从未启动。
下面是我在main()中的代码
pthread_t thread;
printf("Start a thread");
int val = pthread_create(&thread, NULL, threadProc, NULL);
// Setup the stage
stage = internal::get_Stage();
stage->scaleMode = flash::display::StageScaleMode::NO_SCALE;
stage->align = flash::display::StageAlign::TOP_LEFT;
stage->frameRate = 60;
// Ask for a Stage3D context to be created
s3d = var(var(stage->stage3Ds)[0]);
s3d->addEventListener(flash::events::Event::CONTEXT3D_CREATE, Function::_new(initContext3D, NULL));
s3d->addEventListener(flash::events::ErrorEvent::ERROR, Function::_new(context3DError, NULL));
s3d->requestContext3D(flash::display3D::Context3DRenderMode::AUTO,
flash::display3D::Context3DProfile::BASELINE_CONSTRAINED);
// Suspend main() and return to the Flash runloop
AS3_GoAsync();下面是函数
void *threadProc(void *arg)
{
printf("From a thread!");
}threadProc不会被执行。
我找到了this手册页,但我想里面什么都没有。我遗漏了什么?
发布于 2013-03-06 17:17:19
线程永远不会执行,因为它没有机会执行。当它启动时(顺便说一句,你不能依赖它),主程序已经结束了。
将以下行添加到pthread_create之后的main中
pthread_join(thread, NULL);这将等待您的线程完成,然后才允许运行main的线程完成。
请参阅live example
发布于 2014-01-31 06:36:10
这是一个古老的话题,但我觉得我应该澄清一下关于FlasCC(Crossbridge)和线程的人们。根据我的经验(在Adobe论坛上有一个关于这个问题的论坛帖子),"pthread_join“只是锁定了FlasCC 1.0.1及更高版本中的所有内容(也就是Crossbridge也是如此)。不知道为什么它还没有被修复,这是一个非常严重的问题。
如果你用Flash1.0编译,pthread_join不会锁住FlasCC。
至于剩下的问题,我不太确定--只是指"pthread_join“的问题。
https://stackoverflow.com/questions/15242969
复制相似问题