编译和运行Nachos的问题

时间:2014-09-13 04:36:15

标签: nachos

第一个问题:我试图导入stdlib.h以使用malloc()和rand()等函数。我在threadtest.cc,文件夹线程中工作。这是我在

之后得到的错误
#include <stdlib.h>

In file included from ../threads/threadtest.cc:18:0:
/usr/include/stdlib.h:146:33: error: declaration of ‘double atof(const char*) throw ()’ has a different exception specifier
In file included from ../threads/utility.h:57:0,
             from ../threads/system.h:12,
             from ../threads/threadtest.cc:13:
../machine/sysdep.h:62:8: error: from previous declaration ‘double atof(const char*)’
In file included from ../threads/threadtest.cc:18:0:
/usr/include/stdlib.h:149:33: error: declaration of ‘int atoi(const char*) throw ()’ has a different exception specifier
In file included from ../threads/utility.h:57:0,
             from ../threads/system.h:12,
             from ../threads/threadtest.cc:13:
../machine/sysdep.h:61:5: error: from previous declaration ‘int atoi(const char*)’
In file included from ../threads/threadtest.cc:18:0:
/usr/include/stdlib.h:771:60: error: declaration of ‘int abs(int) throw ()’ has a different exception specifier
In file included from ../threads/utility.h:57:0,
             from ../threads/system.h:12,
             from ../threads/threadtest.cc:13:
../machine/sysdep.h:63:5: error: from previous declaration ‘int abs(int)’
../threads/threadtest.cc: In function ‘void shout(int)’:
../threads/threadtest.cc:83:25: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]

这可能是什么原因?

第二个问题:我试图给一个分叉的新线程一个名字。

Thread * t = new Thread ("my id");
t->Fork(shout, S);

在功能呼喊中测试它:

printf ("%s", currentThread->getName());

这个例子很好用。 但是,如果我想给线程一个“动态”id,我使用:

sprintf(id, "%d", i);
Thread * t = new Thread (id);

对于currentThread-&gt; getName()使用相同的printf,它会让我感到垃圾:

x ӿ _

我使用了Nachos文档中的示例,并尝试了使用字符串函数传输动态ID的不同方法,但没有任何效果,只有垃圾。

感谢您的回答。

1 个答案:

答案 0 :(得分:1)

我的Nachos作业遇到了同样的问题。

我的室友说可能是不兼容问题,并建议我删除“stdlib.h”。

有效!