Friday, July 25, 2008

Linux Pthread Programming

在Linux上program要使用到Pthread其實很平常,Socket的相關程式大都會用到。以下是部分程式碼

void *NM_TCP(void *threadarg)
{

    unsigned char *strAddr;
    unsigned int *tcpPort;
    struct thread_data *data;
    data = (struct thread_data *)threadarg;

    strAddr = data->addr;
    tcpPort = data->port;

}

void main()
{
    //parameter for pthread
    struct thread_data{
    U8_T *opcode;
    U8_T *addr;
    U16_T *port;
    };

    struct thread_data trd_data;

    trd_data.addr = inet_ntoa(UDPClntAddr.sin_addr);
    trd_data.opcode = &(SearchPacket.Opcode);
    trd_data.port = &(SearchPacket.TcpPort);

    pthread_create(&nm_threads[thread_idx],NULL,NM_TCP,(void *)&trdData);
}

Reference
https://computing.llnl.gov/tutorials/pthreads/

HEMiDEMi Technorati Del.icio.us MyShare個人書籤 Yahoo

0 意見: