Closed ngng007 closed 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您好,我不完全了解您的情况。函数
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 ?
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.
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.
@ngng007 So you want to use storage functionalities in the old process, or the new process created by fork()
?
@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
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.
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.
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:
40 threads when progress starts :
after daemon() :
attach new progress :
![image](https://user-images.githubusercontent.com/69141858/119482284-45d84200-bd86-11eb-9232-bb933041db6c.png)