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?

Habba
  • 1,179
  • 2
  • 13
  • 32

2 Answers2

0

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

Tony The Lion
  • 61,704
  • 67
  • 242
  • 415
  • Sorry, but not the answer. First of all, the main() does not exit, since it will go indefinite loop due to AS3_GoAsync(). Also, joining thread will cause execution to halt indefinitely. Mayhaps a deadlock? Flash log prints out following: Error: Error #1502: A script has executed for longer than the default timeout period of 15 seconds. at flash.concurrent::Condition/wait() at global/C_Run::threadArbCondWait() – Habba Mar 06 '13 at 10:00
  • 1
    @Habba you cannot expect anyone to go and look for your samples as one thing, and secondly, if you don't post a question that has all information in it, then you can't expect a correct answer. – Tony The Lion Mar 06 '13 at 10:25
  • But if you do not know the samples, you can't have the answer. I'll edit the question to be more precise. – Habba Mar 06 '13 at 10:33
  • @Habba so why the heck, if you know that, did you omit them in the first place? Seriously, you don't deserve your questions answered if you're going to be like that. – Tony The Lion Mar 06 '13 at 10:36
  • Well, I just kinda expected mentioning the environment (stage3d, flascc, flash) would be enough to point out that this isn't the trivial case. Next time I'll just have to be more throughout. – Habba Mar 06 '13 at 10:47
0

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.