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
JieunYoon
battle_c
Commits
3103fac6
Commit
3103fac6
authored
4 years ago
by
JieunYoon
Browse files
Options
Downloads
Patches
Plain Diff
Update README.md
parent
6d80c117
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
08_12_thread/2.mymutexthread_st.c
+0
-87
0 additions, 87 deletions
08_12_thread/2.mymutexthread_st.c
08_12_thread/README.md
+4
-1
4 additions, 1 deletion
08_12_thread/README.md
with
4 additions
and
88 deletions
08_12_thread/2.mymutexthread_st.c
deleted
100644 → 0
+
0
−
87
View file @
6d80c117
#include
<stdio.h>
#include
<stdlib.h>
#include
<string.h>
#include
<pthread.h>
#include
<sys/types.h>
#include
<errno.h>
#include
<unistd.h>
#include
<sys/syscall.h>
void
*
thread_function
(
void
*
);
int
Counter
=
0
;
#ifndef NOMUTEX
....
mutex_id
;
#endif
int
main
(
void
)
{
pthread_t
tid1
,
tid2
;
void
*
thread_result
;
#ifndef NOMUTEX
if
(
________
(
&
mutex_id
,
NULL
)
!=
0
){
perror
(
"pthread_mutex_init"
);
exit
(
errno
);
}
#endif
if
(
_______
(
&
tid1
,
NULL
,
thread_function
,
"thread1"
)
!=
0
)
{
perror
(
"pthread_create"
);
exit
(
1
);
}
if
(
_______
(
&
tid2
,
NULL
,
thread_function
,
"thread2"
)
!=
0
)
{
perror
(
"pthread_create"
);
exit
(
1
);
}
if
(
_______
(
tid1
,
&
thread_result
)
!=
0
)
{
perror
(
"pthread_join"
);
exit
(
1
);
}
if
(
_______
(
tid2
,
&
thread_result
)
!=
0
)
{
perror
(
"pthread_join"
);
exit
(
1
);
}
#ifndef NOMUTEX
___________
(
&
mutex_id
);
#endif
printf
(
" thread result : %s
\n
"
,
(
char
*
)
thread_result
);
return
0
;
}
void
*
thread_function
(
void
*
arg
)
{
int
temp
;
int
i
,
j
;
char
buffer
[
80
];
printf
(
"thread_function called
\n
"
);
for
(
i
=
0
;
i
<
8
;
i
++
)
{
#ifndef NOMUTEX
_________
(
&
mutex_id
);
#endif
sprintf
(
buffer
,
"%s: CountRelay: from %d to "
,
(
char
*
)
arg
,
Counter
);
write
(
1
,
buffer
,
strlen
(
buffer
));
temp
=
Counter
;
temp
=
temp
+
1
;
// delay
for
(
j
=
0
;
j
<
5000000
;
j
++
);
Counter
=
temp
;
sprintf
(
buffer
,
"%d
\n
"
,
Counter
);
write
(
1
,
buffer
,
strlen
(
buffer
));
#ifndef NOMUTEX
__________
(
&
mutex_id
);
#endif
}
// getchar();
_______
(
"thread end"
);
}
This diff is collapsed.
Click to expand it.
08_12_thread/README.md
+
4
−
1
View file @
3103fac6
...
...
@@ -81,8 +81,11 @@ make
89
73
Main start!
====sthread1 start====
합 : 1837, 평균 : 61.233334
====sthread1 end====
Main end!
====sthread2 start====
1등 : 100
2등 : 99
3등 : 96
...
...
@@ -113,7 +116,7 @@ Main end!
28등 : 9
29등 : 4
30등 : 1
====sthread2 end====
```
sthread2가 sthread1보다 연산량이 많아 늦게 끝나는 것을 볼 수 있다.
### 2.mymutexthread.c
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