|
|
@@ -15,10 +15,20 @@ int thread_start(int id, thread_fn fn, void *arg, int stksize, int prio)
|
|
|
|
|
|
h->arg = arg;
|
|
|
h->quit = 0;
|
|
|
- pthread_attr_init(&attr);
|
|
|
- pthread_attr_setstacksize(&attr, stksize);
|
|
|
+
|
|
|
+ r = pthread_attr_init(&attr);
|
|
|
+ if(r) {
|
|
|
+ printf("____ thread %d attr init failed\n", id);
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ r = pthread_attr_setstacksize(&attr, stksize);
|
|
|
+ if(r) {
|
|
|
+ printf("____ thread %d attr setstacksize %d failed\n", id, stksize);
|
|
|
+ }
|
|
|
|
|
|
r = pthread_create(&h->tid, &attr, fn, h);
|
|
|
+ pthread_attr_destroy(&attr);
|
|
|
|
|
|
return r;
|
|
|
}
|
|
|
@@ -68,9 +78,32 @@ int thread_start_simp(thread_fn fn, void *arg, int stksize)
|
|
|
pthread_attr_init(&attr);
|
|
|
pthread_attr_setstacksize(&attr, stksize);
|
|
|
|
|
|
- return pthread_create(&tid, &attr, fn, arg);
|
|
|
+ r = pthread_create(&tid, &attr, fn, arg);
|
|
|
+ pthread_attr_destroy(&attr);
|
|
|
+
|
|
|
+ return r;
|
|
|
}
|
|
|
|
|
|
|
|
|
+int thread_print_stacksize(void)
|
|
|
+{
|
|
|
+ int r;
|
|
|
+ size_t size;
|
|
|
+ pthread_attr_t attr;
|
|
|
|
|
|
+ r = pthread_attr_init(&attr);
|
|
|
+ if(r) {
|
|
|
+ printf("___ print stacksize, attr init failed\n");
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ r = pthread_attr_getstacksize(&attr, &size);
|
|
|
+ if(r) {
|
|
|
+ printf("___ print stacksize, attr init failed\n");
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ printf("_____ stacksize: %dMB\n", size/MB);
|
|
|
+ }
|
|
|
+ pthread_attr_destroy(&attr);
|
|
|
+ return r;
|
|
|
+}
|
|
|
|