SunOS에서 개념 제시, lightweight process
실행 path만을 더 만든다는 개념을 사용한다.
void func1(void *p) { … }
void func2(void *p) { … }
main()
{
func1(…);
func2(…);
…
}
void func1(void *p) { … }
void func2(void *p) { … }
main()
{
thread_create(func1, …);
thread_create(func2, …);
…
}
While (1) {
int sock = accept();
if ((pid = fork()) == 0) {
/* Handle client request */
} else {
/* Close socket */
}
}
webserver ()
{
While (1) {
int sock = accept();
thread_fork (handle_request, sock);
}
}
handle_request (int sock)
{
/* Process request */
close (sock);
}
pthread_join : tid가 끝나길 기다리는 명령어
int pthread_create (pthread_t *tid, pthread_attr_t *attr, void *(start_routine)(void *), void *arg);
void pthread_exit (void *retval);
int pthread_join (pthread_t tid, void **thread_return);
int pthread_mutex_init (pthread_mutex_t *mutex, const pthread_mutexattr_t *mattr);
int pthread_mutex_destroy (pthread_mutex_t *mutex);
int pthread_mutex_lock (pthread_mutex_t *mutex);
int pthread_mutex_unlock (pthread_mutex_t *mutex);
int pthread_cond_init (pthread_cond_t *cond, const pthread_condattr_t *cattr);
int pthread_cond_destroy (pthread_cond_t *cond);
int pthread_cond_wait (pthread_cond_t *cond, pthread_mutex_t *mutex);
int pthread_cond_signal (pthread_cond_t *cond);
int pthread_cond_broadcast (pthread_cond_t *cond);
HANDLE CreateThread (lpThreadAttributes, dwStackSize, lpStartAddress, lpParameter, dwCreationFlags, lpThreadId);
void ExitThread (dwExitCode);
Create a new class derived from Thread class Override run() method
Create a new class that implements the runnable interface