## Parallel computing
### Parallel computing
연산을 병렬적으로 처리하여 계산하는 방식, multi thread는 그중 하나의 방식이다.
### Mutex
여러 스레드가 공유하는 데이터를 보호하기 위한 도구, 한번에 하나의 스레드만 실행가능하도록 하는 방법
### Posix thread
병렬 소프트웨어의 작성을 위해 제공되는 표준 API, `<pthread.h>`에서 제공하고 있다.
**스레드 생성함수**
```c
int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
void *(*start_routine)(void *), void *arg);
thread : 식별자
attr : 스레드 특성 지정
routine : 스레드 함수
arg : 스레드 함수 인자
```
**스레드 대기 함수(=wait)**
```c
int pthread_join(pthread_t th, void **thread_return);
th : 식별자
thread_return : 스레드의 리턴값
```
**스레드 분리 함수**
join되지 않아도 종료시 자원이 모두 해제됨
```c
int pthread_detach(pthread_t th);
th : 식별자
```
**스레드 동기화 함수**
```c
int pthread_mutex_init(pthread_mutex_t * mutex,
const pthread_mutex_attr *attr);
mutex : 공유 자원 식별자
attr : 특성 변화
("fast"(default), "recursev", "error checking")
```
**mutex 제거함수**
```c
int pthread_mutex_destroy(pthread_mutex_t *mutex);
```
**mutex 작업, 프리 함수**
```c
int pthread_mutex_lock(pthread_mutex_t *mutex);
int pthread_mutex_unlock(pthread_mutex_t *mutex);
```
### 세마포어
공유자원에 대한 접근을 관리하는 변수, 이진세마포어(0, 1)와 컴퓨팅 세마포어(도메인 제한X)로 나뉜다.