CC=gcc
BIN=libthreads
-SOURCE=libthreads.c schedule.c libatomic.c
+SOURCE=libthreads.c schedule.c libatomic.c userprog.c
HEADERS=libthreads.h schedule.h common.h libatomic.h
FLAGS=-Wall
return current;
}
-void a(int *parm)
-{
- int i;
-
- for (i = 0; i < 10; i++) {
- printf("Thread %d, magic number %d, loop %d\n", thread_current()->index, *parm, i);
- if (i % 2)
- thread_yield();
- }
-}
-
-void user_main()
-{
- struct thread t1, t2;
- int i = 17, j = 13;
-
- printf("%s() creating 2 threads\n", __func__);
- thread_create(&t1, &a, &i);
- thread_create(&t2, &a, &j);
-
- thread_join(&t1);
- thread_join(&t2);
- printf("%s() is finished\n", __func__);
-}
-
int main()
{
struct thread user_thread;
int thread_yield(void);
struct thread *thread_current(void);
+extern void user_main(void);
+
#endif /* __LIBTHREADS_H__ */
--- /dev/null
+#include <stdio.h>
+
+#include "libthreads.h"
+#include "libatomic.h"
+
+static void a(atomic_int *obj)
+{
+ int i;
+
+ for (i = 0; i < 10; i++) {
+ printf("Thread %d, loop %d\n", thread_current()->index, i);
+ if (i % 2)
+ atomic_load(obj);
+ }
+}
+
+void user_main()
+{
+ struct thread t1, t2;
+ atomic_int obj;
+
+ printf("%s() creating 2 threads\n", __func__);
+ thread_create(&t1, &a, &obj);
+ thread_create(&t2, &a, &obj);
+
+ thread_join(&t1);
+ thread_join(&t2);
+ printf("%s() is finished\n", __func__);
+}