pthread_create on android


#1

I have thread function like this:

static void* ThreadFunction(void *o)
{
    CCMessageBox("ThreadFunction", "MainLayer");
    return NULL;
}

And create thread like this:

pthread_t thread;
CCMessageBox("pthread_create", "MainLayer");
pthread_create(&thread, NULL, ThreadFunction, 0);

On windows all works fine: i see 2 messages. On android i see only first message(“pthread_create”)

I tryed to create thread in onEnter, onClick, constructor methods.
I am using cocos2d-x 2.0.4. Can somebody help me?


#2

I heard about “CCMessageBox is using the OpenGL context, at least on mobile devices OpenGL functions must be run on the same thread the GL context was created on”.

But without CCMessageBox, i have inside ThreadFunc image download using curl. It is not working at all. What’s wrong?


#3
  • Use CCLOG to trace app execution path.
  • Use CCHttpClient to perform network operations on background thread

#4

Thank you for CCHttpClient.