cThread

来源:互联网 发布:vscode 好用的插件 编辑:程序博客网 时间:2024/06/06 12:33

//

//  cThread.h

//  myTask

//

//  Created by user on 12-4-10.

//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.

//


#ifndef myTask_cThread_h

#define myTask_cThread_h

#include <stdio.h>


class textThread

{

private:

    

public:

    textThread();

    static void myThread();

    void init();

    static void * thread(void*);

};


#endif

//

//  cThread.mm

//  myTask

//

//  Created by user on 12-4-10.

//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.

//


#include <pthread.h>

#include <stdio.h>

#include <iostream>

#include "cThread.h"


textThread::textThread()

{

    NSAutoreleasePool *pool = [[NSAutoreleasePoolalloc]init];

    init();

    [pool release];


}

void * textThread::thread(void *para)

{

    int i;

    for(i=0;i<3;i++)

    printf("This is a pthread.\n");

    returnNULL;

}

voidtextThread::init()

{

    pthread_tid;

    int ret;

    /*int       pthread_create(pthread_t * __restrict,

     const pthread_attr_t * __restrict,

     void *(*)(void *),

     void * __restrict);*/

    ret = pthread_create(&id,NULL,thread, this);

    if(ret!=0){

         printf ("Create pthread error!\n");

        exit (1);

    }

}