惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

A
Arctic Wolf
T
The Blog of Author Tim Ferriss
月光博客
月光博客
Recent Announcements
Recent Announcements
V
V2EX
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - 三生石上(FineUI控件)
P
Proofpoint News Feed
The Register - Security
The Register - Security
博客园 - 叶小钗
博客园 - Franky
The Cloudflare Blog
雷峰网
雷峰网
罗磊的独立博客
M
MIT News - Artificial intelligence
I
InfoQ
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 【当耐特】
Engineering at Meta
Engineering at Meta
N
Netflix TechBlog - Medium
爱范儿
爱范儿
博客园 - 司徒正美
Recorded Future
Recorded Future
酷 壳 – CoolShell
酷 壳 – CoolShell
Google DeepMind News
Google DeepMind News
Martin Fowler
Martin Fowler
Microsoft Security Blog
Microsoft Security Blog
F
Full Disclosure
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
B
Blog
大猫的无限游戏
大猫的无限游戏
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
腾讯CDC
WordPress大学
WordPress大学
小众软件
小众软件
K
Kaspersky official blog
Attack and Defense Labs
Attack and Defense Labs
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Forbes - Security
Forbes - Security
aimingoo的专栏
aimingoo的专栏
IT之家
IT之家
The Last Watchdog
The Last Watchdog
N
News and Events Feed by Topic
B
Blog RSS Feed
S
Security @ Cisco Blogs
美团技术团队
量子位
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Cloudbric
Cloudbric
Hacker News - Newest:
Hacker News - Newest: "LLM"

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python) The Hidden Cost of AI Systems Nobody Talks About. undefined vs undeclared, and how typeof behaves Switching from file-based jobs to NATS/Kafka in Rust without changing code io_uring Adventures: Rust Servers That Love Syscalls Why Agentic AI is Killing the Traditional Database The POUR principles of web accessibility for developers and designers Quantum Neural Network 3D — A Deep Dive into Interactive WebGL Visualization How To Install Caveman In Codex On macOS And Windows Automation Pipeline Reliability: Why Your Workflow Breaks When Nobody Is Watching I Built an 'Open World' AI Coding Agent — It Works From ANY Folder From Freelancing to Product: A Tech Service Company's SaaS Transformation China's AI Giants: Adding Tencent Hunyuan & ByteDance Doubao to AI University (74 Providers) On the Vibe Coders and Their Lies clerk: Auto-Summarize Your Claude Code Sessions AI Weekly — 2026/04/10–04/17 | The Model Lockdown Is Here, but the Toolchain Is the Real Battleground AI 週報 — 2026/04/10–2026/04/17 模型封鎖潮來了,但工具鏈才是真戰場 Maybe this is how Open-Source apps are born... 🚀 Fine-Tune LLMs with LoRA and QLoRA: 2026 Guide tRPC v11 + Next.js App Router: End-to-End Type Safety Without the Boilerplate ShadCN UI in 2026: Why I Stopped Installing Component Libraries and Started Owning My Components SaaS Billing in React Server Components: Stripe + Supabase Without a Single `useEffect` Join our DEV Weekend Challenge — $1,000 in Prizes Across TEN winners! Submissions Due April 20 at 6:59 AM UTC. Implementing FSRS Spaced Repetition in Flutter + Supabase — Adding Memory Science to an AI Learning App "I Texted My Localhost From the Train — Claude Code Fixed the Bug Before I Got Home" I Built a Sales Prep AI and It Went Deeper Than Expected Design to Code #2: One JSON, Eleven Outputs Solving the 100M-Row Problem: A Summary Table Pattern for High-Volume Push Notification Logs Flutter Web With Wasm: What Actually Changes For Developers I Built 50 Royalty-Free Soundtracks for My Side Project in a Weekend Using AI Music Generation The Vibe Coding Security Checklist: 7 Things to Check Before You Ship Stop Letting Googlebot Guess Fix Your React App's SEO Right Desconstruindo o Streaming do LinkedIn: Como Criar um Engine de Extração de Vídeo de Alta Performance com HLS e FFmpeg (EDA Part-1) EDA (Exploratory Data Analysis) Explained With Real Life — Why Looking at Your Data Is the Most Important Step in Machine Learning Brand Relationship Management at Scale: Our 4-Touch Outreach System for 200+ Brands Why String.fromEnvironment() Might Return an Empty String in Dart JGuardrails 1.0.0 — Hardening Java LLM Apps Against Jailbreaks, Toxicity, and Prompt Injection Plan and Schedule a Full Week of Threads Content From One Claude Conversation Coding Cat Oran Ep3, Five Tables Changed Everything Updated: BFF Pattern I'm done watching freelancers get buried by 200 proposals. So I'm building the alternative. This is my first post BFS Algorithm in Java Step by Step Tutorial with Examples Tracking LLM Pricing Monthly: An Open Dataset for 22 AI Models How We Measure Content ROI on a Comparison Site: Revenue Attribution Without Perfect Data Introducing Nova AI Ops: The AI-Native Operating System for SRE Teams I built a free desktop video downloader for Windows — Grabbit How Talkie OCR Helps Vision-Impaired & Dyslexic Users Read the World Around Them VRCFaceTracking安装和iPhone面捕配置教程,有bug Even CrowdStrike Can't See Your Agents The Automation Gold Rush: What n8n Workflows and Claude Are Opening Up for Developers Right Now
Goroutines in Rust
David Berry · 2026-06-03 · via DEV Community

Building go-lib: A Chronicle

How a faithful port of Go's M:N scheduler came to life in Rust.

The Idea

The Rust language doesn't pick a single concurrency model, instead, it provides primitives and ownership rules that make any model safe to implement. Unlike Java (virtual threads), Go (goroutines + channels) or Erlang (actor model), Rust ships without a runtime or a preferred style. The asynchronous working group and the async-std libraries were unsuccessful attempts to add concurrency to the language. The async-std library has been abandoned in favor of smol. The asynchronous working group has not met in years.

The standard library gives you:

  • std::thread — OS threads, nothing more
  • std::sync::{Mutex, RwLock, Condvar, Barrier} — shared-state primitives
  • std::sync::mpsc — a multi-producer/single-consumer channel

That's it. Everything else — async/await, actors, work-stealing executors, lock-free data structures — lives in the ecosystem (tokio, rayon, crossbeam, actix, etc.).

I needed a concurrency model for another project and started researching smol and tokio. In researching tokio I found that the tokio scheduler is based on the go scheduler. This prompted me to look for a goroutines crate, and ultimately writing my own implementation.

Why goroutines

Go has one of the most elegant concurrency models in any systems language: goroutines that start tiny and grow, channels that block without burning threads, a work-stealing scheduler that squeezes every CPU core. The question was whether that model could be brought to Rust — not via async/await, not by wrapping tokio, but by porting Go's actual runtime, source file by source file, into safe-ish Rust.

The answer became go-lib: a crate that lets you write:

go_lib::run(|| {
    let (tx, rx) = go_lib::chan::chan::<String>(0);
    for i in 0..5 {
        let tx = tx.clone();
        go!(move || tx.send(format!("hello from goroutine {i}")));
    }
    drop(tx);
    while let Some(msg) = rx.recv() { println!("{msg}"); }
});

Enter fullscreen mode Exit fullscreen mode

No async, no executor, no tokio — just goroutines.

The Implementation

I chose Claude to be the primary implementor of go-lib. This complex project was a perfect candidate for Claude. I had not yet used Claude for developing a project end-to-end and wanted the experience. Spoiler alert, I had to do more work than I imagined.

The Plan

I like to iterate on a plan with Claude before starting large initiatives. I can get my thoughts written down and refine them into a solid working plan. I chose to use Opus for creating the plan and started with this prompt:

Please create a step by step plan to port goroutines from go to rust. It should utilize as many of the native rust constructs as possible, eg Channels.

Claude created a plan to expose

tokio::spawn(async move { … }), as go! macro

and implement channels using flume.

This was not what I wanted. Claude did not understand what I meant by "port" so I needed to refine the plan. As it turns out, the entire project was a series of me asking Claude to do something, and then making course corrections as we went along.

My second prompt:

update the steps to remove the use of tokio, and include porting the scheduler and other missing parts from the go repo: https://github.com/golang/go

Claude understood now. Claude created an acceptable plan:

Phase A — Scaffolding and low-level primitives

  1. Crate layout.
  2. Port the Gobuf / register save area (runtime/runtime2.go).
  3. Implement gogo and mcall in src/runtime/asm_arm64.rs (and x86_64 sibling).
  4. Stack allocator (runtime/stack.go → src/runtime/stack.rs).

Phase B — The G/M/P scheduler

  1. Port G (src/runtime/g.rs) from runtime2.go.
  2. Port M (src/runtime/m.rs).
  3. Port P (src/runtime/p.rs) and its runqueue.
  4. Port the scheduler core (src/runtime/sched.rs) from proc.go.
  5. Bootstrap (src/runtime/sched.rs: schedinit/main).
  6. Port sysmon (src/runtime/sysmon.rs).
  7. Cooperative preemption only.

Phase C — Channels, synchronization

  1. Port sudog (src/runtime/sudog.rs).
  2. Port hchan (src/chan.rs) from chan.go.
  3. Port select (src/select.rs) from select.go.
  4. Port WaitGroup (src/sync/waitgroup.rs) from sync/waitgroup.go.
  5. Port sync.Mutex (src/sync/mutex.rs) from sync/mutex.go.

Phase D — Timers, polish, ergonomics

  1. Port timer heap (src/runtime/time.rs) from time.go.
  2. Public API and macros (src/lib.rs, src/go_macro.rs).
  3. Tests and examples.
  4. Known-skipped, called out in docs. GC integration, stack growth/copying, async preemption via signals, netpoll, race detector, cgo, defer/recover, GOMAXPROCS at runtime. Each is a future phase.

One thing I noticed is that channels and mutexes were being ported over from go, when they already exist in rust. I questioned whether the rust thread and mutex can be reused. Mutexes could be reused, channels could not as they did not align with the channels in go. Claude updated the plan to use the rust mutex. Another thing to note is step 20, the things that Claude is leaving out for future phases. I chose to implement them right away, but that may not have been the best decision.

The Code

I switched to Sonnet and had Claude proceed with step 1. When it was done, I had it proceed with step 2. We did this for all 20 steps. In hindsight, it would have been good to test the working code after step 19. Testing after step 20 caused multiple levels of errors that were harder to track down. In fact, Claude had to disable some features from step 20 to be able to isolate problems from the first 19 steps.

Claude did a great job porting the code, (go, asm) -> (rust, asm). I certainly could not have done this in the same timeframe. Claude also included doc comments, doc tests, unit tests, and integrations tests in the port. When Claude got the project to the point where all tests passed, it said it was done. Little did I know the work was just beginning.

It took about 3 days to get to this point. This is mostly due to me running out of tokens and having to wait 3 hours to refresh my session. I also learned that it is better to prompt Claude on how to proceed after running out of tokens, rather than hitting "try again" on the error screen. Prompting

Continue where you left off, implementing xxx

works well.

Testing

Initially the tests were flaky. Sometimes they would pass and sometimes they would fail. You can waste a lot of time with Claude, and I did, having Claude try and find the errors causing flaky tests. It is always better having a test which causes the error consistently or at least at a higher percentage of time.

The best way to test a library is to use the library. Once I felt that go_lib was reasonably stable, I put it to use. The project that inspired me to find a better concurrency model is the one I used to test go-lib. I immediately found two features needed to make the library more usable: A runtime attribute; and scope.

The original api required that the contents of main() were wrapped in a go_lib::run(|| {}); block. I thought that using a runtime attribute is cleaner, so I had Claude add the #[go_lib::run] attribute. The second missing feature is scope. Migrating my test project using std::thread::scope to using just go! was complicated, so I had Claude add go_lib::scope to the library. Now using scoped go functions is as simple as

let data = vec![1_i64, 2, 3, 4, 5];

let sum = go_lib::scope(|s| {
    let h1 = s.go(|| data[..3].iter().sum::<i64>());
    let h2 = s.go(|| data[3..].iter().sum::<i64>());
    h1.join().unwrap() + h2.join().unwrap()
});

Enter fullscreen mode Exit fullscreen mode

Once the features were implemented, I had everything I needed to start using go_lib. The first attempt at using go_lib exposed errors and hangs. My test project creates 10s of thousands of goroutines, and go_lib could not handle it. I tried having Claude use the test project to debug go_lib, but it was too confusing for Claude. It kept telling me that my test project was creating too many goroutines and that I should create work groups of smaller number of goroutines.

The solution was to create a test, many_goroutines, and set the workers to a large number. This would give Claude an in-project integration test that it can use to resolve the issues. This was the longest phase of this project, helping Claude find the most subtle hangs and panics. Claude would sometimes increase memory or stack sizes to make problems go away, and it would be necessary to reiterate some requirements such as, goroutines use a 2KB stack.

Humorously, Claude would tell me of "pre-existing" bugs, when it is investigating one bug and finds a different bug. If the bug was from earlier commits it would say that the bug was a "pre-existing bug not from my changes".

Documentation

Just a note on documentation. I had to prompt Claude to go back and check for stale documentation, comments, and README.md. I was okay with this, as I would do it once before tagging and pushing out a new version.

Where It Stands

go-lib v0.5.0 is a working, tested implementation of Go-style concurrency in Rust with no async machinery. The runtime passes CI across Ubuntu x86-64, macOS AArch64, and Windows x86-64 in both standard and loom model-check configurations.

Async preemption via SIGURG is fully operational. The full chain — sysmon fires, signal handler redirects RIP, trampoline saves RFLAGS + all GPRs + XMM registers, scheduler yields, trampoline restores, goroutine resumes — is correct, tested at 75_000 concurrent goroutines, and free of known crash modes.

The stack growth path works correctly for the common case (frames smaller than the initial stack size). The correct long-term fix — morestack-style compiler-generated stack checks at every function entry — remains future work; the current guard-page approach cannot intercept a single frame larger than the initial stack size.

Goroutines work. Channels work. Select works. Scope works. The scheduler steals work. Goroutines preempt. Stacks grow. RFLAGS round-trips correctly across a yield.

It runs.