TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

So you want to live-reload Rust (2020)

25 pointsby sea6earover 3 years ago

4 comments

throwaway81523over 3 years ago
This is about reloading dynlibs, technically cool I guess, but maybe asking for trouble. I prefer to launch a new process, then transfer any open connections and fd&#x27;s with the SCM_RIGHTS auxiliary message under Linux.<p>I once asked Joe Armstrong (RIP) about Erlang&#x27;s famous hot reload feature compared to doing something like that, and he agreed with me that hot reload wasn&#x27;t really worthwhile, as sexy as it might sound.
评论 #28862840 未加载
10000truthsover 3 years ago
The most common reason to want this is for long running programs with a plug-in architecture. Here’s my advice, for use cases where the plug-in and the plug-in loader are both under your control:<p>1. Don’t directly dlopen the .so file. Copy it to a temporary file and dlopen that. Much fewer headaches that way when the original .so file changes. Bonus points for using Linux’s memfd or FreeBSD’s SHM_ANON.<p>2. Rely as little on global&#x2F;thread-local state as possible in the plug-in. Minimize the use of non-reentrant function calls in exported functions.<p>3. Don’t use musl. Its dlclose is a no-op and will cause memory leaks.<p>4. If the plug-in is to be accessed across multiple threads, copy the symbols you’ll need from the plug-in into a struct, and maintain a reference count alongside the struct. When reloading the plug-in, create a new struct for all new threads to use, and free the old struct when its reference count goes to zero.
jbrotover 3 years ago
Another excellent article from Amos digging into the minutiae of how executables work!
WalterGRover 3 years ago
(2020)