Fix occasional deadlock caused by checkpoint root marking.

There was a race where a new worker thread would attach during the
checkpoint. This caused the thread to wait since suspend count != 0.
But when we decremented the suspend count, we did not broadcast to
the resume condition.

Added a create peer parameter to Thread::Attach and
AttachCurrentThread. This is used by the threadpool since we don't
need a java peer for worker threads.

Change-Id: I632926b5a6b52eeb0684b6e1dcbf3db42ba3d35c
diff --git a/src/thread.cc b/src/thread.cc
index f6e7249..00aaabd 100644
--- a/src/thread.cc
+++ b/src/thread.cc
@@ -308,7 +308,8 @@
   thread_list->Register(this);
 }
 
-Thread* Thread::Attach(const char* thread_name, bool as_daemon, jobject thread_group) {
+Thread* Thread::Attach(const char* thread_name, bool as_daemon, jobject thread_group,
+                       bool create_peer) {
   Thread* self;
   Runtime* runtime = Runtime::Current();
   if (runtime == NULL) {
@@ -335,7 +336,7 @@
   // so that thread needs a two-stage attach. Regular threads don't need this hack.
   // In the compiler, all threads need this hack, because no-one's going to be getting
   // a native peer!
-  if (self->thin_lock_id_ != ThreadList::kMainId && !Runtime::Current()->IsCompiler()) {
+  if (create_peer) {
     self->CreatePeer(thread_name, as_daemon, thread_group);
   } else {
     // These aren't necessary, but they improve diagnostics for unit tests & command-line tools.