Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
battle_c
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
BeomSooHeo
battle_c
Commits
1f517c94
Commit
1f517c94
authored
4 years ago
by
BeomSooHeo
Browse files
Options
Downloads
Patches
Plain Diff
Update thread.md
parent
02e0714b
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
thread/thread.md
+18
-17
18 additions, 17 deletions
thread/thread.md
with
18 additions
and
17 deletions
thread/thread.md
+
18
−
17
View file @
1f517c94
# thread
# thread
. 2020_08_12
## 1. discription
## 1. discription
Input: 사용자로부터 short형 정수 30개를 입력 받는다.
Input: 사용자로부터 short형 정수 30개를 입력 받는다.
<br><br>
main function:
main function: pthread_create를 이용해 Thread를 2개 생성하고 thread가 종료될 때까지 기다린다.
<br>
<br>
Thread를 2개 생성하고 thread가 종료될 때까지 기다린다.
Thread sth_1 :
Thread sth_1 :
전달받은 void 형 포인터를 short형 포인터로 변환한 후
전달받은 void 형 포인터를 short형 포인터로 변환한 후
<br>
포인터가 가리키는 배열의 모든 element의 총합과
포인터가 가리키는 배열의 모든 element의 총합과 이를 평균을 낸 결과를 출력한다.
<br><br>
이를 평균을 낸 결과를 출력한다.
Thread sth_2 :
Thread sth_2 :
전달받은 void 형 포인터를 short형 포인터로 변환한 후
전달받은 void 형 포인터를 short형 포인터로 변환한 후
<br>
bubble_sort를 통해 포인터가 가리키는 배열의 모든 element를 내림차순 정렬한 후 출력한다.
bubble_sort를 통해 포인터가 가리키는 배열의 모든 element를 내림차순 정렬한 후 출력한다.
<br><br>
## 2. result
## 2. result
[사진1]
<br>
<br>

<br><br>
pthread.h를 사용하기 위해서
pthread.h를 사용하기 위해서
gcc 컴파일시 -lpthread 링크 설정을 해주어야한다.
gcc 컴파일시 -lpthread 링크 설정을 해주어야한다.
[사진2]
<br><br>

<br>
<br>
<br>
1부터 30까지 입력을 하였고,
1부터 30까지 입력을 하였고,
입력이 제대로 이뤄졌는지 확인하기 위해 입력한 배열을 다시 출력하였고, 정상적으로 입력이 완료되었음을 확인할 수 있다.
입력이 제대로 이뤄졌는지 확인하기 위해 입력한 배열을 다시 출력하였고, 정상적으로 입력이 완료되었음을 확인할 수 있다.
sth_1(첫번째 thread)은 입력값의 총합과 평균을 출력하고,
sth_1(첫번째 thread)은 입력값의 총합과 평균을 출력하고,
[사진3]
<br><br>
<br>

<br><br>
sth_2(두번째 thread)는 입력값을 높은 값부터 차례대로 내림차순 정렬하여 출력했다.
sth_2(두번째 thread)는 입력값을 높은 값부터 차례대로 내림차순 정렬하여 출력했다.
출력의 형식은 n번째 : value 의 의미이다.
마지막으로, pthread_join을 이용하여 main thread는 child thread들이 종료될 때까지 기다리도록하게 했다.
마지막으로, pthread_join을 이용하여 main thread는 child thread들이 종료될 때까지 기다리도록하게 했다.
따라서 thread의 종료 순서는 sth_1 -> sth_2 -> main thread 순이 되었다.
따라서 thread의 종료 순서는 sth_1 -> sth_2 -> main thread 순이 되었다.
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment