因此,我下载了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手册页,但我认为那里没有任何内容。我想念什么?
最佳答案
线程永远不会执行,因为它没有机会。在开始运行时(您可能无法依靠它),主程序已经完成。
将以下行添加到main
之后的pthread_create
中:
pthread_join(thread, NULL);
这将等待您的线程完成,然后再允许运行
main
的线程完成。见live example
关于c - Stage3D和pthreads,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15242969/