This seems kind-of OK (I personally think pthread_detach is always messy
and in 99.9% of cases a bad idea). What you do need to (somehow) ensure
is that you do MHD_resume_connection() (and let it finish) *before*
calling MHD_stop_daemon().

On 3/16/20 8:00 PM, silvioprog wrote:
> Hi.
> 
> I have a routine which suspends a MHD connection and calls the following
> functions when it starts:
> 
> 1. MHD_suspend_connection()
> 2. pthread_create()
> 3. pthread_detach()
> 
> and the following when it finishes:
> 
> 1. MHD_resume_connection()
> 2. /some callback()/
> 3. pthread_exit()
> 
> but the server may be stopped by the user and return from main() before
> the stages 2 and 3 above get finished, however, the pthread_create(3)
> <https://linux.die.net/man/3/pthread_create> says: "/The new thread
> terminates in one of the following ways: - Any of the threads in the
> process calls exit(3), or the main thread performs a return from main().
> This causes the termination of all threads in the process/".
> 
> I thought it would be necessary to add some lockable list (with mutex)
> in the server to iterate all the threads and cancel them before
> finishing the server, but it seems I don't need it, since all the
> threads are already exited with main thread, and my application don't
> need to stop gracefully.
> 
> So, can I follow using such design and run it in production?
> 
> TIA for any suggestions!
> 
> --
> Silvio Clécio

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to