简体   繁体   中英

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?

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM