Incorrect Linux/POSIX behaviour after main thread exits

While looking into supporting threaded debugging on FreeBSD I
discovered an issue in the Linux implementation.

ProcessPOSIX::SendMessage now looks up a POSIXThread in m_thread_list
by tid, but is called from ::MonitorCallback with the pid of the
process. As it happens this usually works on Linux, because the first
(or only) thread's tid is equal to the pid, resulting in a successful
FindThreadByID. However, this fails if the main thread exits.

I set up a Debian VM to explore this, and the test case below causes
lldb to hang.

#include <pthread.h>
#include <stdlib.h>
#include <unistd.h>

void *
thread(void *arg)

main(int argc, char *argv)
        pthread_t td;
        pthread_create(&td, NULL, thread, NULL);

        return 0;

Any objection to the following patch, which improves threaded
debugging on FreeBSD, and should have no effect on Linux for the
currently working cases?

diff --git a/source/Plugins/Process/POSIX/ProcessPOSIX.cpp
index 6f25585..cbdb27a 100644
--- a/source/Plugins/Process/POSIX/ProcessPOSIX.cpp
+++ b/source/Plugins/Process/POSIX/ProcessPOSIX.cpp
@@ -373,6 +373,14 @@ ProcessPOSIX::SendMessage(const ProcessMessage &message)

     POSIXThread *thread = static_cast<POSIXThread*>(
         m_thread_list.FindThreadByID(message.GetTID(), false).get());
+ // FIXME: We overload the message's tid by setting it to either a tid or a
+ // pid. For now provide the first thread if provided the pid and no match
+ // is found.
+ if (!thread && message.GetTID() == GetID())
+ {
+ thread = static_cast<POSIXThread*>(
+ m_thread_list.GetThreadAtIndex(0, false).get());
+ }

     switch (message.GetKind())