Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
pcc022
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
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
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
이소현
pcc022
Commits
eb6eedc0
Commit
eb6eedc0
authored
3 years ago
by
이소현
Browse files
Options
Downloads
Patches
Plain Diff
lec14
parent
08dd7aee
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
lec13/th3.c
+4
-2
4 additions, 2 deletions
lec13/th3.c
lec14/prtest.c
+12
-0
12 additions, 0 deletions
lec14/prtest.c
lec14/th4.c
+35
-0
35 additions, 0 deletions
lec14/th4.c
lec14/threadtest.c
+48
-0
48 additions, 0 deletions
lec14/threadtest.c
with
99 additions
and
2 deletions
lec13/th3.c
+
4
−
2
View file @
eb6eedc0
...
...
@@ -7,14 +7,14 @@ int bbb = 0;
void
fn_s
()
{
static
int
a
=
0
;
printf
(
"== %d %d ==
\n
"
,
a
++
,
bbb
++
);
printf
(
"== %d %d =="
,
a
++
,
bbb
++
);
}
void
*
run
(
void
*
arg
)
{
printf
(
"Hello world of POSXI threads.%d
\n
"
,
(
int
)
(
0
)
);
for
(
int
i
=
0
;
i
<
10
0
;
i
++
)
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
sleep
(
1
);
fn_s
();
...
...
@@ -26,6 +26,8 @@ void *run (void *arg)
int
main
()
{
int
result1
;
char
bufff
[
10
];
setvbuf
(
stdout
,
bufff
,
_IOFBF
,
10
);
run
((
void
*
)
0
);
sleep
(
10
);
...
...
This diff is collapsed.
Click to expand it.
lec14/prtest.c
0 → 100644
+
12
−
0
View file @
eb6eedc0
#include
<stdio.h>
int
main
()
{
char
a
;
short
b
;
int
c
;
long
long
d
;
scanf
(
"%hhd %hd %d %lld"
,
&
a
,
&
b
,
&
c
,
&
d
);
printf
(
"%hhd %hd %d %lld
\n
"
,
a
,
b
,
c
,
d
);
}
This diff is collapsed.
Click to expand it.
lec14/th4.c
0 → 100644
+
35
−
0
View file @
eb6eedc0
#include
<stdio.h>
#include
<sys/types.h>
#include
<unistd.h>
int
bbb
=
0
;
void
fn_s
()
{
static
int
a
=
0
;
printf
(
"== %d %d =="
,
a
++
,
bbb
++
);
fflush
(
stdout
);
}
void
*
run
(
void
*
arg
)
{
printf
(
"Hello world of POSIX threads.%d
\n
"
,
(
int
)
(
0
)
);
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
sleep
(
1
);
fn_s
();
}
return
0
;
}
int
main
()
{
int
result1
;
// char bufff[10];
// setvbuf(stdout,bufff, _IONBF, 10);
run
((
void
*
)
0
);
printf
(
"Thread return %d at the end
\n
"
,
result1
);
}
This diff is collapsed.
Click to expand it.
lec14/threadtest.c
0 → 100644
+
48
−
0
View file @
eb6eedc0
#include
<stdio.h>
#include
<sys/types.h>
#include
<unistd.h>
#include
<stdlib.h>
#include
<pthread.h>
int
bbb
=
0
;
void
fn_s
()
{
static
pthread_mutex_t
mutex
=
PTHREAD_MUTEX_INITIALIZER
;
static
int
a
=
0
;
printf
(
"<= %d %d =>"
,
a
,
bbb
);
pthread_mutex_lock
(
&
mutex
);
a
++
;
bbb
++
;
pthread_mutex_unlock
(
&
mutex
);
}
void
*
run
(
void
*
arg
)
{
printf
(
"Hello world of POSXI threads.%d
\n
"
,
(
int
)
pthread_self
()
);
for
(
int
i
=
0
;
i
<
1000
;
i
++
)
{
//usleep(10000);
fn_s
();
}
return
0
;
}
int
main
()
{
pthread_t
thread1
;
pthread_t
thread2
;
pthread_t
thread3
;
int
result1
,
result2
,
result3
;
pthread_create
(
&
thread1
,
NULL
,
run
,
NULL
);
pthread_create
(
&
thread2
,
NULL
,
run
,
NULL
);
pthread_create
(
&
thread3
,
NULL
,
run
,
NULL
);
run
((
void
*
)
0
);
pthread_join
(
thread1
,
(
void
**
)
&
result1
);
pthread_join
(
thread2
,
(
void
**
)
&
result2
);
pthread_join
(
thread3
,
(
void
**
)
&
result3
);
printf
(
"
\n
Thread return %d at the end
\n
"
,
result1
);
}
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