|
|
@@ -8,6 +8,8 @@
|
|
|
#include "../device/ioqueue.h"
|
|
|
#include "../device/keyboard.h"
|
|
|
#include "../userprog/process.h"
|
|
|
+#include "../userprog/syscall-init.h"
|
|
|
+#include "../lib/user/syscall.h"
|
|
|
|
|
|
void kernel_thread_a_func(void *);
|
|
|
void kernel_thread_b_func(void *);
|
|
|
@@ -15,6 +17,7 @@ void user_prog_a(void *);
|
|
|
void user_prog_b(void *);
|
|
|
|
|
|
int test_var_a = 0, test_var_b = 0;
|
|
|
+int prog_a_pid = 0, prog_b_pid = 0;
|
|
|
|
|
|
int main(void)
|
|
|
{
|
|
|
@@ -28,12 +31,16 @@ int main(void)
|
|
|
// put_int((uintptr_t)addr);
|
|
|
// put_str("\n");
|
|
|
|
|
|
- thread_start("kernel_thread_a_func", 31, kernel_thread_a_func, "argA ");
|
|
|
- thread_start("kernel_thread_a_func", 31, kernel_thread_b_func, "argB ");
|
|
|
process_execute(user_prog_a, "user_prog_a");
|
|
|
// process_execute(user_prog_b, "user_prog_b");
|
|
|
|
|
|
intr_enable(); // 打开中断,使中断起作用
|
|
|
+ console_put_str(" main_pid:0x");
|
|
|
+ console_put_int(sys_getpid());
|
|
|
+ console_put_str("\n");
|
|
|
+
|
|
|
+ thread_start("kernel_thread_a_func", 31, kernel_thread_a_func, "argA ");
|
|
|
+ thread_start("kernel_thread_a_func", 31, kernel_thread_b_func, "argB ");
|
|
|
// 主线程会一直执行, 直到被中断或被其他线程强制结束
|
|
|
while (1)
|
|
|
;
|
|
|
@@ -41,36 +48,38 @@ int main(void)
|
|
|
}
|
|
|
|
|
|
/*在线程中运行的函数*/
|
|
|
-void kernel_thread_a_func(void *UNUSED(arg))
|
|
|
+void kernel_thread_a_func(void *arg)
|
|
|
{
|
|
|
// 用 void 来表示通用类型,这样就可以传递任意类型的参数
|
|
|
- while (1)
|
|
|
- {
|
|
|
- console_put_str("v_a:0x");
|
|
|
- console_put_int(test_var_a);
|
|
|
- }
|
|
|
+ char *para = arg;
|
|
|
+ console_put_str(" thread_a_pid:0x");
|
|
|
+ console_put_int(sys_getpid());
|
|
|
+ console_put_char('\n');
|
|
|
+ console_put_str(" prog_a_pid:0x");
|
|
|
+ console_put_int(prog_a_pid);
|
|
|
+ console_put_char('\n');
|
|
|
}
|
|
|
-void kernel_thread_b_func(void *UNUSED(arg))
|
|
|
+void kernel_thread_b_func(void *arg)
|
|
|
{
|
|
|
- while (1)
|
|
|
- {
|
|
|
- console_put_str(" v_b:0x");
|
|
|
- console_put_int(test_var_b);
|
|
|
- }
|
|
|
+ char *para = arg;
|
|
|
+ console_put_str(" thread_b_pid:0x");
|
|
|
+ console_put_int(sys_getpid());
|
|
|
+ console_put_char('\n');
|
|
|
+ console_put_str(" prog_b_pid:0x");
|
|
|
+ console_put_int(prog_b_pid);
|
|
|
+ console_put_char('\n');
|
|
|
}
|
|
|
|
|
|
/*测试用户进程*/
|
|
|
void user_prog_a(void *UNUSED(arg))
|
|
|
{
|
|
|
+ prog_a_pid = getpid();
|
|
|
while (1)
|
|
|
- {
|
|
|
- test_var_a++;
|
|
|
- }
|
|
|
+ ;
|
|
|
}
|
|
|
void user_prog_b(void *UNUSED(arg))
|
|
|
{
|
|
|
+ prog_b_pid = getpid();
|
|
|
while (1)
|
|
|
- {
|
|
|
- test_var_b++;
|
|
|
- }
|
|
|
+ ;
|
|
|
}
|