projects
/
model-checker.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
478b0e8
)
libthreads: fixups
author
Brian Norris
<banorris@uci.edu>
Fri, 9 Mar 2012 07:36:20 +0000
(23:36 -0800)
committer
Brian Norris
<banorris@uci.edu>
Fri, 9 Mar 2012 07:36:20 +0000
(23:36 -0800)
libthreads.c
patch
|
blob
|
history
libthreads.h
patch
|
blob
|
history
diff --git
a/libthreads.c
b/libthreads.c
index 6da8fbf6a6604b89ddaa7286289a88c9105cd1a7..2326f3b1839e965c64b35050e4fb8384d102cc5c 100644
(file)
--- a/
libthreads.c
+++ b/
libthreads.c
@@
-1,6
+1,5
@@
#include <string.h>
#include <stdlib.h>
#include <string.h>
#include <stdlib.h>
-#include <ucontext.h>
//#define CONFIG_DEBUG
//#define CONFIG_DEBUG
@@
-48,10
+47,10
@@
static int create_initial_thread(struct thread *t)
int thread_create(struct thread *t, void (*start_routine), void *arg)
{
static int created = 1;
int thread_create(struct thread *t, void (*start_routine), void *arg)
{
static int created = 1;
- ucontext_t local;
DBG();
DBG();
+ memset(t, 0, sizeof(*t));
t->index = created++;
DEBUG("create thread %d\n", t->index);
t->index = created++;
DEBUG("create thread %d\n", t->index);
@@
-84,15
+83,15
@@
void a(int *idx)
void user_main()
{
struct thread t1, t2;
void user_main()
{
struct thread t1, t2;
- int i =
1, j = 2
;
+ int i =
2, j = 3
;
thread_create(&t1, &a, &i);
thread_create(&t2, &a, &j);
thread_create(&t1, &a, &i);
thread_create(&t2, &a, &j);
- printf("
user_main() is going to start 2 threads\n"
);
+ printf("
%s() is going to start 1 thread\n", __func__
);
thread_start(&t1);
thread_start(&t2);
thread_start(&t1);
thread_start(&t2);
- printf("
user_main() is finished\n"
);
+ printf("
%s() is finished\n", __func__
);
}
int main()
}
int main()
@@
-103,7
+102,6
@@
int main()
current = &main_thread;
thread_create(&user_thread, &user_main, NULL);
current = &main_thread;
thread_create(&user_thread, &user_main, NULL);
-
thread_start(&user_thread);
DBG();
thread_start(&user_thread);
DBG();
diff --git
a/libthreads.h
b/libthreads.h
index 8522871771aeb7f7569e3df819581b449f2e75d9..1323cef896f3603b4518d09f8a754e61af94e7c4 100644
(file)
--- a/
libthreads.h
+++ b/
libthreads.h
@@
-1,4
+1,8
@@
+#ifndef __LIBTHREADS_H__
+#define __LIBTHREADS_H__
+
#include <stdio.h>
#include <stdio.h>
+#include <ucontext.h>
#ifdef CONFIG_DEBUG
#define DBG() do { printf("Here: %s, L%d\n", __func__, __LINE__); } while (0)
#ifdef CONFIG_DEBUG
#define DBG() do { printf("Here: %s, L%d\n", __func__, __LINE__); } while (0)
@@
-18,3
+22,5
@@
struct thread {
int thread_create(struct thread *t, void (*start_routine), void *arg);
void thread_start(struct thread *t);
int thread_create(struct thread *t, void (*start_routine), void *arg);
void thread_start(struct thread *t);
+
+#endif /* __LIBTHREADS_H__ */