lock tchild_table in terminal_input

without this lock, its possible for terminal_delete
to free a child object while we are writing to the
terminal. with this change a terminal_delete call
will have to wait for the writer to finish.
switch order of locking g_tchild_table and other locks

since we need to lock g_tchild_table before the child
struct in terminal_input, we have to reorder locks
in terminal_new and terminal_delete. i forgot that
when a child is locked, all the screen + global
resources are implicitly locked along with it. but
in terminal_{new,delete} we were locking the screen +
global resources before locking g_tchild_table, which
could cause deadlock. (thanks helgrind! :D )
Merge branch 'lock-tchild-table'