Threads
The main()
function starts the main bitcoind process thread, usefully named bitcoind
. All subsequent threads are currently started as children of the bitcoind
thread, although this is not an explicit design requirement.
The Bitcoin Core Developer docs contains a section on threads, which is summarised below in two tables, one for net threads, and one for other threads.
Name | Function | Description |
---|---|---|
|
| Responsible for starting up and shutting down the application, and spawning all sub-threads |
|
| Loads blocks from |
|
| Parallel script validation threads for transactions in blocks |
|
| Libevent thread to listen for RPC and REST connections |
|
| HTTP worker threads. Threads to service RPC and REST requests |
|
| Indexer threads. One thread per indexer |
|
| Does asynchronous background tasks like dumping wallet contents, dumping |
|
| Libevent thread for tor connections |
Net threads
Name | Function | Description |
---|---|---|
|
| Application level message handling (sending and receiving). Almost all |
|
| Loads addresses of peers from the |
|
| Universal plug-and-play startup/shutdown |
|
| Sends/Receives data from peers on port 8333 |
|
| Opens network connections to added nodes |
|
| Initiates new connections to peers |
|
| Listens for and accepts incoming I2P connections through the I2P SAM proxy |
Thread debugging
In order to debug a multi-threaded application like bitcoind using gdb you will need to enable following child processes. Below is shown the contents of a file threads.brk
which can be sourced into gdb using source threads.brk
, before you start debugging bitcoind. The file also loads break points where new threads are spawned.
set follow-fork-mode child
break node::ThreadImport
break StartScriptCheckWorkerThreads
break ThreadHTTP
break StartHTTPServer
break ThreadSync
break SingleThreadedSchedulerClient
break TorControlThread
break ThreadMessageHandler
break ThreadDNSAddressSeed
break ThreadMapPort
break ThreadSocketHandler
break ThreadOpenAddedConnections
break ThreadOpenConnections
break ThreadI2PAcceptIncoming