Azure / azure-storage-cpp

Microsoft Azure Storage Client Library for C++
http://azure.github.io/azure-storage-cpp
Apache License 2.0
131 stars 147 forks source link

Daemon() causes thread pool threads to exit on Centos #399

Closed ngng007 closed 3 years ago

ngng007 commented 3 years ago

I found that azurestorage will start 40 threads for blob requests when the progress is started, but my project needs the progress to run in the background, so daemon() worked, but this will lead to no threads in the background process. How can I solve this problem? Forgive me for my terrible English. test program: image 40 threads when progress starts : image after daemon() : image attach new progress : image

Jinming-Hu commented 3 years ago

Hi @ngng007 , I don't fully understand your scenario. What does function daemon() do? My guess is daemon() will create a detached thread, which will keep running even after main() exits. But all the 40 threads will be released after main() exits, then all storage functionalities don't work in the detached thread anymore. Is that the problem you're trying to solve?

ngng007 commented 3 years ago

@ ngng007您好,我不完全了解您的情况。函数daemon()有什么作用?我的猜测是daemon()将创建一个分离的线程,即使main()退出后该线程也将继续运行。但是所有40个线程将在main()退出后释放,然后所有存储功能将不再在分离的线程中起作用。那是您要解决的问题吗?

Yes, thank you for your answer, how can I solve this problem? Is there any way I can reinitialize the thread pool in the new process ?

Jinming-Hu commented 3 years ago

Yes, thank you for your answer, how can I solve this problem? Is there any way I can reinitialize the thread pool in the new process ?

The only way I can think of is to keep main process running until daemon() returns. You can make it a background process, this should have the same effect as a detached thread.

This is more of a thread/process lifetime management question, rather than a storage-specific question.

ngng007 commented 3 years ago

the threads will released when daemon() returned, not main exits, i found that daemon() will use fork() to get a new process, fork() only copies the thread that currently calls it, so that 40 threads are lost. now i use 'nohup' to make it in background, but that's not what I want.

Jinming-Hu commented 3 years ago

@ngng007 So you want to use storage functionalities in the old process, or the new process created by fork()?

ngng007 commented 3 years ago

@ngng007 So you want to use storage functionalities in the old process, or the new process created by fork()?

i want to use storage functionalities in new process by fork(), because old process will exit, and new process runs in background

Jinming-Hu commented 3 years ago

Unfortunately, there's no way to get around this issue as far as I know. Storage SDK will initialize the thread pool once the process starts, which I believe is a bad design.

@ngng007 Are you starting a new project? If so, you can try out new Track2 Storage SDK.

ngng007 commented 3 years ago

Unfortunately, there's no way to get around this issue as far as I know. Storage SDK will initialize the thread pool once the process starts, which I believe is a bad design.

@ngng007 Are you starting a new project? If so, you can try out new Track2 Storage SDK.

thanks,maybe I really need to consider this new SDK. The current SDK has too many dependent libraries.