cocos2d-x,Ios里面多线程的用法

代码如下:

void *threadProcessFunction(void *ptr)

{

printf("enter thread\n");

//do thread thing


//exit thread

printf("exit thread\n");

return NULL;

}

void startRequestThread()

{

    // Create the thread using POSIX routines.

    pthread_attr_t  attr;

    pthread_t       posixThreadID;

    int             returnVal;

    

    returnVal = pthread_attr_init(&attr);

    assert(!returnVal);

    returnVal = pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_DETACHED);

    assert(!returnVal);

    int threadError = 0;


    threadError = pthread_create(&posixThreadID, &attr, &threadProcessFunction, (void*)value);

    returnVal = pthread_attr_destroy(&attr);

    assert(!returnVal);

    if (threadError != 0)

    {

        printf("create thread error");

    }

}
posted @ 2012-02-06 17:10  MXi4oyu  阅读(274)  评论(0编辑  收藏  举报