浏览代码

all: several makefile corrections and organization steps

Douglas Andreani 5 年之前
父节点
当前提交
113d3d75ab
共有 4 个文件被更改,包括 74 次插入10 次删除
  1. 5 0
      .gitignore
  2. 13 1
      pthread/Makefile
  3. 49 9
      pthread/example.c
  4. 7 0
      x11-random/Makefile

+ 5 - 0
.gitignore

@@ -27,4 +27,9 @@ _testmain.go
 
 .vscode/
 *.exe
+<<<<<<< HEAD
 >>>>>>> 1cc34e1... global gitignore
+=======
+*.o
+*/bin/*
+>>>>>>> aacc961... all: several makefile corrections and organization steps

+ 13 - 1
pthread/Makefile

@@ -1,4 +1,5 @@
 CC=/usr/bin/gcc
+<<<<<<< HEAD
 CFLAGS=-Wall -Werror -fno-builtin -O0 -g -pthread -m64 -std=iso9899:1999
 OBJ=bin/obj
 OBJS=$(OBJ)/example.o $(OBJ)/example2.o $(OBJ)/foo.o
@@ -15,4 +16,15 @@ bin/obj/example.o: example.c
 	$(CC) $(CFLAGS) -c -o $(OBJ)/example.o example.c
 
 bin/obj/example2.o: example2.c
-	$(CC) $(CFLAGS) -c -o $(OBJ)/example2.o example2.c
+	$(CC) $(CFLAGS) -c -o $(OBJ)/example2.o example2.c
+=======
+CFLAGS=-Wall -Werror -fno-builtin -O0 -g -pthread -m64 -std=iso9899:1990
+OBJ=bin/obj
+OBJS=$(OBJ)/example.o
+
+all: $(OBJS)
+	$(CC) $(CFLAGS) -o bin/example $(OBJS)
+
+bin/obj/example.o:
+	$(CC) $(CFLAGS) -c -o bin/obj/example.o example.c
+>>>>>>> 78289eb... all: several makefile corrections and organization steps

+ 49 - 9
pthread/example.c

@@ -1,19 +1,59 @@
-#include "example.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <pthread.h>
 
-int fib(int n)
+struct fibo {
+	int limit;
+	int answer;
+};
+
+int 
+fib(int n)
 {
-	int i = 0;
-	if (n == 1 || n == 0)
-		return 1;
-	for (i = 0; i < n; i++) {
-		return (fib(n - 1) + fib(n - 2));
+	int i=0;
+	if (n==1 || n==0) return 1;
+	for(i=0;i<n;i++){
+		return (fib(n-1) + fib(n-2));
 	}
 	return (-1);
 }
 
-void *runner1(void *arg)
+void*
+runner1(void* arg)
 {
-	struct fibo *fibl = (struct fibo *) arg;
+	struct fibo* fibl = (struct fibo*) arg;
 	fibl->answer = fib(fibl->limit);
 	pthread_exit(0);
 }
+
+int
+main (int argc, char** argv)
+{
+	
+	int i;
+	pthread_t id[argc];
+	pthread_attr_t attr;
+	struct fibo d[argc];
+
+	if (argc < 2) {
+		printf("usage: %s num1 num2 num3... numN", argv[0]);
+		return (1);
+	}
+
+	
+
+	pthread_attr_init(&attr);
+	for (i=1; i<argc;i++){
+		d[i-1].limit = atoi(argv[i]);
+		d[i-1].answer = 0;
+		pthread_create(&id[i-1], &attr, runner1, &d[i-1]);
+	}
+
+	for (i=0;i<argc-1;i++){
+		pthread_join(id[i], NULL);
+		printf("\n\nFib of limit: %d is %d", d[i].limit, d[i].answer);
+	}
+
+	return (0);
+
+}

+ 7 - 0
x11-random/Makefile

@@ -5,12 +5,19 @@ OBJ=$(OUT)/obj
 OBJS=$(OBJ)/worley_noise.o
 
 
+<<<<<<< HEAD
 all: bin/worley_noise
 
 bin/worley_noise: $(OBJS)
 	$(CC) $(CFLAGS) $(OBJS) -o $(OUT)/worley_noise
 
 bin/obj/worley_noise.o: worley_noise.c
+=======
+all: $(OBJS)
+	$(CC) $(CFLAGS) $(OBJS) -o $(OUT)/worley_noise
+
+bin/obj/worley_noise.o:
+>>>>>>> 78289eb... all: several makefile corrections and organization steps
 	$(CC) $(CFLAGS) -c worley_noise.c -o $(OBJ)/worley_noise.o
 
 clean: