public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] [gdb/dap] Join JSON writer thread with DAP thread
@ 2024-02-21  9:46 Tom de Vries
  0 siblings, 0 replies; only message in thread
From: Tom de Vries @ 2024-02-21  9:46 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=7c34de9efdb13fff482ed0c4de0dffee1e1880f3

commit 7c34de9efdb13fff482ed0c4de0dffee1e1880f3
Author: Tom de Vries <tdevries@suse.de>
Date:   Wed Feb 21 10:46:08 2024 +0100

    [gdb/dap] Join JSON writer thread with DAP thread
    
    The DAP interpreter runs in its own thread, and starts a few threads:
    - the JSON reader thread,
    - the JSON writer thread, and
    - the inferior output reader thread.
    
    As part of the DAP shutdown, both the JSON reader thread and the JSON writer
    thread, as well as the DAP main thread run to exit, but these exits are not
    ordered in any way.
    
    Wait in the main DAP thread for the exit of the JSON writer thread.
    
    This makes sure that the responses are flushed to the DAP client before DAP
    shutdown.
    
    An earlier version of this patch used Queue.task_done() to accomplish the
    same, but that didn't guarantee writing the "<thread name>: terminating"
    log entry from thread_wrapper before DAP shutdown.
    
    Tested on aarch64-linux.
    
    Approved-By: Tom Tromey <tom@tromey.com>
    
    PR dap/31380
    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31380

Diff:
---
 gdb/python/lib/gdb/dap/io.py      | 2 +-
 gdb/python/lib/gdb/dap/server.py  | 3 ++-
 gdb/python/lib/gdb/dap/startup.py | 1 +
 3 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/gdb/python/lib/gdb/dap/io.py b/gdb/python/lib/gdb/dap/io.py
index 4edd504c727..81e835c7527 100644
--- a/gdb/python/lib/gdb/dap/io.py
+++ b/gdb/python/lib/gdb/dap/io.py
@@ -79,4 +79,4 @@ def start_json_writer(stream, queue):
             stream.write(body_bytes)
             stream.flush()
 
-    start_thread("JSON writer", _json_writer)
+    return start_thread("JSON writer", _json_writer)
diff --git a/gdb/python/lib/gdb/dap/server.py b/gdb/python/lib/gdb/dap/server.py
index 7cc5a4681ee..e7110660741 100644
--- a/gdb/python/lib/gdb/dap/server.py
+++ b/gdb/python/lib/gdb/dap/server.py
@@ -212,7 +212,7 @@ class Server:
         # Before looping, start the thread that writes JSON to the
         # client, and the thread that reads output from the inferior.
         start_thread("output reader", self._read_inferior_output)
-        start_json_writer(self.out_stream, self.write_queue)
+        json_writer = start_json_writer(self.out_stream, self.write_queue)
         start_thread("JSON reader", self._reader_thread)
         while not self.done:
             cmd = self.read_queue.get()
@@ -229,6 +229,7 @@ class Server:
         # JSON-writing thread, so that we can ensure that all
         # responses are flushed to the client before exiting.
         self.write_queue.put(None)
+        json_writer.join()
 
     @in_dap_thread
     def send_event_later(self, event, body=None):
diff --git a/gdb/python/lib/gdb/dap/startup.py b/gdb/python/lib/gdb/dap/startup.py
index 60491212c67..0a42c91e8f4 100644
--- a/gdb/python/lib/gdb/dap/startup.py
+++ b/gdb/python/lib/gdb/dap/startup.py
@@ -80,6 +80,7 @@ def start_thread(name, target, args=()):
 
     result = gdb.Thread(name=name, target=thread_wrapper, args=args, daemon=True)
     result.start()
+    return result
 
 
 def start_dap(target):

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-02-21  9:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-21  9:46 [binutils-gdb] [gdb/dap] Join JSON writer thread with DAP thread Tom de Vries

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).