On Thu, Feb 2, 2017 at 5:19 PM, Justin Cinkelj <justin.cink...@gmail.com>
wrote:

>
>
>> I think we can do something similar (at least to 1-3). Instead of my
>> previous patch, do something like this:
>>
>> 1. httpserver uses osv::run_background() to run the background operation,
>> and receives an osv::application object.
>> 2. httpserver holds a map of numeric id to pair of
>> weak_ptr<osv::application> (?) and another map for exit code, giving a new
>> integer id to each application (these will not be related to actual process
>> ID).
>> 3. A new function like osv::application::join_terminated() will return
>> an array of already terminated apps. The httpserver will save their exit
>> codes and unreference the actual application so it can be destructed. Of
>> course we need to recognize terminated applications correctly :-(
>> 4. A new rest API will query the exit code of an application with a given
>> ID.
>> 5. Note we can't ever delete the exit code, even after we return it,
>> because it is always possible the client didn't receive the response and
>> may try the same request again...
>>
>>
>> Does this sound reasonable?
>>
>> If you didn't need the actual exit code - just to know if the application
>> is still running, things would be slightly simpler because we just need to
>> maintain a list of still-running apps and their ids, and not remember
>> anything about old apps.
>>
>
> 1. is implemented and commited now
>
> 2. I would prefer if this is not httpserver specific; httpserver should
> only consume the applications' exit status etc. So maybe a weak_ptr can be
> inserted into map for _each_ new app (in the application::application(), or
> maybe a bit later, when the thread is already constructed).
> I would prefer to keep thread ID as the key - it has some meaning (can be
> used in gdb, can be checked in REST dashboard) and I don't see any need to
> hide it. So first map is <thread_id, weak_ptr<app>>. Second map is
> <thread_id, exit_code>.
>
> Would this be acceptable?
>

I wouldn't like to add an unordered_map<thread_id, weak_ptr<app>> outside
the httpserver, because frankly, I don't understand who else would want to
use it except httpserver. Why don't you want it to be in httpserver?

On the other hand, the osv::application::run() is already so messy, that I
guess it won't be such a big loss to add even more mess to it ;-)

I didn't understand why you need the second map <thread_id, exit_code>. Is
it so we can retrieve the exit code of the thread after joining it (e.g.,
with a new join_terminated() function to clean zombies)? Or retrieve the
exit code of the same thread multiple times? In this case, it seems to me
an even more httpserver specific use case, and it makes even more sense to
me to do it in httpserver and not in some general OSv code.

Nadav.

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to osv-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to