Skip to content
Advertisement

Linux – Get the start and end of the stack memory for a thread

I am trying to port something to Linux. My original code (for a RTOS) looks like:

int stackSize = 4*1024;
void* stack = malloc(stackSize);
int thread = create_thread(stack, FuncToRun)

Later the stack and stackSize are used by the garbage collector and to get some thread statistics.

Now, how do I convert the above code to Linux?

Advertisement

Answer

You should use Pthread:

int stackSize = 4*1024;

pthread_attr_t atrib_thread;
pthread_attr_init(&atrib_thread);
pthread_attr_setstacksize(&atrib_thread,stackSize);

pthread_t my_thread;
pthread_create(&my_thread,&atrib_thread,FuncToRun,NULL);

http://www.manpagez.com/man/3/pthread_attr/

http://www.manpagez.com/man/3/pthread_create/

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement