libmicrohttpd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [libmicrohttpd] Double regarding suspended connection and pthread_ex


From: Christian Grothoff
Subject: Re: [libmicrohttpd] Double regarding suspended connection and pthread_exit
Date: Mon, 16 Mar 2020 20:29:01 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0

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

[Prev in Thread] Current Thread [Next in Thread]