boost thread throwing exception “thread_resource_error: resource temporarily unavailable”

前端 未结 2 1435
旧巷少年郎
旧巷少年郎 2020-11-28 15:36

I have code similar to the following code

boost::thread myThread
unsigned char readbuffer[bignumber];
unsigned char writebuffer[bignumber];

for(int i=0; i&l         


        
2条回答
  •  星月不相逢
    2020-11-28 15:59

    First, I wasn't explicitly killing off my threads with thread.join() or thread.detach() so the total number of threads would grow out of control and throw an exception.

    Also, in my inner loop I was creating two threads but keeping only one handle. So I lost control of 1 thread each iteration of the outer loop causing the total number of threads to grow past the prescribed limit of threads causing the exception.

    To retain unique handles to the threads created in the inner loop I added them into a boost::group and used a myGroup.join_all(). I suppose I also could have used a vector to push the handles onto and then popped them off to join them all.

    boost::thread_group myThreadGroup
    unsigned char readbuffer[bignumber];
    unsigned char writebuffer[bignumber];
    
    for(int i=0; i

提交回复
热议问题