0

First issue: I am trying to import stdlib.h in order to use functions like malloc() and rand(). I am working in threadtest.cc , folder threads. This is the error I get after

#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]

What can be a reason for this?

Second issue: I am trying to give a forked new thread a name.

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

And testing it in function shout:

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

This example works fine. However, if I want to give the thread a "dynamic" id, I use:

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

With the same printf for currentThread->getName() it gets me junk:

x�ӿ����_ ���

I have used example from the Nachos documentation as well as tried different ways to transmit a dynamic id using string functions, but nothing worked, only junk.

Thank you for any answers.

Madrugada
  • 1,261
  • 8
  • 24
  • 44

1 Answers1

1

I had the same problem in my Nachos homework.

My roommate said maybe it's a incompatibility problem, and suggested that I delete "stdlib.h".

It worked!

Jay
  • 11
  • 1