gpt4 book ai didi

c - Stage3D 和 pthreads

转载 作者:行者123 更新时间:2023-11-30 17:54:03 24 4
gpt4 key购买 nike

所以我下载了 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手册页,但我认为那里没有任何内容。我错过了什么?

最佳答案

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

将以下行添加到 pthread_create 之后的 main 中:

 pthread_join(thread, NULL);

这将等待您的线程完成,然后才允许运行 main 的线程完成。

参见live example

关于c - Stage3D 和 pthreads,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15242969/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com