Commit fe0cf888 authored by Zhaozhong Liu's avatar Zhaozhong Liu
Browse files

update prelab

parent 95558249
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)
......@@ -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 %ld\n", T);
PthreadCreate(&threads[t], NULL, PrintChar, (void *)T);
for(T=0; T<NUM_THREADS; T++){
printf("The thread %ld has been created\n", T);
PthreadCreate(&threads[T], NULL, PrintChar, (void *)T);
}
pthread_exit(NULL);
......
......@@ -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);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment