Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Zhaozhong Liu
csci315
Commits
fe0cf888
Commit
fe0cf888
authored
Sep 14, 2021
by
Zhaozhong Liu
Browse files
update prelab
parent
95558249
Changes
3
Hide whitespace changes
Inline
Side-by-side
Labs/Lab3/Makefile
0 → 100644
View file @
fe0cf888
CC
=
gcc
CFLAGS
=
-std
=
gnu99
-Wall
-g
#-DDEBUG
LFLAGS
=
-lpthread
-lm
EXECS
=
pthread_hello time_demo mergesort
all
:
EXECS
warppers.o
:
wrappers.h wrappers.c
$(CC)
$(CFLAGS)
-c
wrappers.c wrappers.h
-o
wrappers.o
char-threads
:
char-threads.c wrappers.o
$(CC)
$(CFLAGS)
-o
$@
$<
wrappers.o
$(LFLAGS)
mytime
:
mytime.c
$(CC)
$(CFLAGS)
-o
$@
$<
$(LFLAGS)
summation
:
summation.c
$(CC)
$(CFLAGS)
-o
$@
$<
$(LFLAGS)
.PHONY
:
clean
clean
:
/bin/rm
-f
*
.o
$(EXECS)
Labs/Lab3/char-threads.c
View file @
fe0cf888
...
...
@@ -2,15 +2,7 @@
#include <stdio.h>
#include <stdlib.h>
#define NUM_THREADS 3
int
PthreadCreate
(
pthread_t
*
thread
,
const
pthread_attr_t
*
attr
,
void
*
(
*
start_routine
)
(
void
*
),
void
*
arg
)
{
int
RET
;
if
(
RET
=
pthread_create
(
thread
,
attr
,
start_routine
,
arg
))
{
perror
(
"Thread failed"
);
exit
(
-
1
);
}
return
RET
;
};
#include "wrappers.h"
void
*
PrintChar
(
void
*
threadid
)
{
long
TID
;
...
...
@@ -47,12 +39,11 @@ void *PrintChar(void *threadid) {
int
main
(
int
argc
,
char
*
argv
[])
{
pthread_t
threads
[
NUM_THREADS
];
int
RC
;
long
T
;
for
(
T
=
0
;
t
<
NUM_THREADS
;
T
++
){
printf
(
"
In main: creating thread %l
d
\n
"
,
T
);
PthreadCreate
(
&
threads
[
t
],
NULL
,
PrintChar
,
(
void
*
)
T
);
for
(
T
=
0
;
T
<
NUM_THREADS
;
T
++
){
printf
(
"
The thread %ld has been create
d
\n
"
,
T
);
PthreadCreate
(
&
threads
[
T
],
NULL
,
PrintChar
,
(
void
*
)
T
);
}
pthread_exit
(
NULL
);
...
...
Labs/Lab3/mytime.c
View file @
fe0cf888
...
...
@@ -3,10 +3,11 @@
#include <time.h>
int
main
(
int
argc
,
char
*
argv
[])
{
struct
timeval
struct_time
;
gettimeofday
(
&
struct_time
,
NULL
);
struct
timeval
struct_time
;
//to make a timeval type object "struct_time"
//bc a pointer to this type of struct is required by the gettimeofday()function
gettimeofday
(
&
struct_time
,
NULL
);
//gettimeof day will store a time_c type into "struct_time"
char
*
CTIMESTR
=
ctime
(
&
struct_time
.
tv_sec
);
printf
(
"Ctime String: %s"
,
CTIMESTR
;
char
*
CTIMESTR
=
ctime
(
&
struct_time
.
tv_sec
);
//ctime converts time_t type to a string.
printf
(
"Ctime String: %s"
,
CTIMESTR
)
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment