0

So I downloaded flascc, and messed around with the sample.

sample 09 (threads) and sample 12 (stage3D) worked well by themselves, but when I tried to run threads in Stage3D sample, they were never started.

Here's a code I have in 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();

and here's the function

void *threadProc(void *arg)
{
      printf("From a thread!");
}

threadProc never gets executed.

I found this manual page, but I don't think there's anything there. What am I missing?

4

2 回答 2

0

老话题,但我觉得我应该为那些窥探 FlasCC(Crossbridge) 和线程的人澄清一下。根据我的经验,“pthread_join”(Adobe 论坛上有一个关于此的论坛主题)只是将所有内容锁定在 FlasCC 1.0.1 和转发(即对于 Crossbridge 相同)。不知道为什么它还没有修复,这是一个非常严重的问题。

如果您使用 FlasCC 1.0 编译 pthread_join 不会锁定 Flash。

至于问题的其余部分,我不确定 - 只是指“pthread_join”问题。

于 2014-01-30T22:36:10.190 回答
0

线程永远不会被执行,因为它没有机会。当它开始时(顺便说一句,你不能依赖它),主程序已经完成了。

将以下行添加到您的mainafter pthread_create

 pthread_join(thread, NULL);

这将在允许main运行的线程完成之前等待您的线程完成。

查看实时示例

于 2013-03-06T09:17:19.107 回答