27 #include <sys/socket.h>
28 #include <netinet/in.h>
42 return pthread_attr_init(attr);
55 void *(*func)(
void*),
void *arg)
62 handle = CreateThread( NULL,
64 (LPTHREAD_START_ROUTINE)func,
67 (
unsigned long *) &ThreadId
70 if(handle == NULL)
return -1;
73 int ret = pthread_create(tid,attr,func,arg);
82 CloseHandle((HANDLE) *tid);
84 if(tid == NULL)
return;
98 ptr = (DWORD *) status;
99 if(status == NULL) ExitThread((DWORD) 0);
100 else ExitThread(*ptr);
102 pthread_exit(status);
121 GetExitCodeThread((HANDLE) tid,&exitcode);
122 if(exitcode != STILL_ACTIVE)
return exitcode;
128 DWORD dwWait = WaitForSingleObject((HANDLE) tid, INFINITE);
129 if(dwWait == WAIT_OBJECT_0)
131 if(GetExitCodeThread((HANDLE) tid, &exitcode) == TRUE)
134 *status = (int) exitcode;
138 result = GetLastError();
141 else if(dwWait == WAIT_FAILED)
143 result = GetLastError();
149 return pthread_join(tid,status);
162 HANDLE handle = CreateMutex(NULL, FALSE, NULL);
163 if(handle) *mptr = handle;
167 return pthread_mutex_init(mptr,attr);
182 return pthread_mutex_destroy(mptr);
193 if(WaitForSingleObject(*mptr, INFINITE) == WAIT_OBJECT_0)
return 0;
197 return pthread_mutex_lock(mptr);
217 ret = WaitForSingleObject(*mptr, 0);
218 if(ret == WAIT_OBJECT_0)
return 1;
225 ret = pthread_mutex_trylock(mptr);
226 if(ret == EBUSY)
return 0;
242 return pthread_mutex_unlock(mptr);
253 return (
int) CloseHandle((HANDLE) tid);
255 return pthread_cancel(tid);
285 pthread_cond_init(&s->cond, NULL);
312 if(!ReleaseSemaphore(
323 pthread_mutex_lock(&s->mutex);
324 if(s->nready == 0) pthread_cond_signal(&s->cond);
326 pthread_mutex_unlock(&s->mutex);
343 ret = WaitForSingleObject(
351 pthread_mutex_lock(&s->mutex);
352 while(s->nready == 0)
354 pthread_cond_wait(&s->cond,&s->mutex);
357 pthread_mutex_unlock(&s->mutex);
371 fd_set wset,rset,eset;
372 struct timeval timeout;
377 timeout.tv_sec = msec / 1000;
378 timeout.tv_usec = (msec % 1000) * 1000;
379 select(1,&rset,&wset,&eset,&timeout);
384 struct timespec interval;
386 interval.tv_sec = msec / 1000;
387 interval.tv_nsec = (msec % 1000) * 1000 * 1000;
388 pthread_delay_np(&interval);
422 void *thread(
void *arg)
425 printf(
"thread start : %s\n",(
const char *) arg);
429 printf(
"thread %d\n",i);
460 printf(
"create a thread\n");
479 printf(
"main %d\n",i);
481 if(i%4 == 0) Sleep(10);
484 printf(
"waiting for thread\n");