Stage3D and pthreads

362 Views Asked by At

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?

2

There are 2 best solutions below

0
On

Old topic, but I feel I should clarify for people snooping around FlasCC(Crossbridge) and threads. "pthread_join" in my experience(and there's a forum thread at Adobe forums about that) simply locks everything in FlasCC 1.0.1 and forward(ie same for Crossbridge). No clue why it hasn't been fixed yet, it's a very serious issue.

If you compile with FlasCC 1.0 pthread_join doesn't lock up Flash.

As for the rest of the question, I'm not sure - just refering to the "pthread_join" issue.

5
On

The thread is never executed because it doesn't have a chance. By the time it gets started (which by the way you can't rely on) the main program has already finished.

Add the following line to your main after pthread_create:

 pthread_join(thread, NULL);

and this will wait on your thread to finish before it allows the thread in which main runs to finish.

See live example