{"id":31929503,"url":"https://github.com/sandtreader/rust-tokio-dylib","last_synced_at":"2025-10-14T03:24:40.535Z","repository":{"id":259084180,"uuid":"876279438","full_name":"sandtreader/rust-tokio-dylib","owner":"sandtreader","description":"Test playground for Tokio in dynamic libraries","archived":false,"fork":false,"pushed_at":"2024-10-21T17:47:44.000Z","size":3,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-22T08:21:59.592Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sandtreader.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-21T17:44:40.000Z","updated_at":"2024-10-21T17:47:48.000Z","dependencies_parsed_at":"2024-10-23T00:02:52.697Z","dependency_job_id":null,"html_url":"https://github.com/sandtreader/rust-tokio-dylib","commit_stats":null,"previous_names":["sandtreader/rust-tokio-dylib"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/sandtreader/rust-tokio-dylib","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sandtreader%2Frust-tokio-dylib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sandtreader%2Frust-tokio-dylib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sandtreader%2Frust-tokio-dylib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sandtreader%2Frust-tokio-dylib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sandtreader","download_url":"https://codeload.github.com/sandtreader/rust-tokio-dylib/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sandtreader%2Frust-tokio-dylib/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279017786,"owners_count":26086144,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-14T02:00:06.444Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-10-14T03:24:39.295Z","updated_at":"2025-10-14T03:24:40.529Z","avatar_url":"https://github.com/sandtreader.png","language":"Rust","readme":"# rust-tokio-dylib\n\nThis is a test playground for Tokio in Rust dynamic libraries.  Currently it\ndemonstrates that if you pass the runtime explicitly to the library and\ncall it directly it can work fine in single-threaded mode, but not in\nmulti-threaded.\n\n## What's going on\n\nIn `main/src/main.rs` we create a runtime, either multi- or single-threaded\ndepending on the RUNTIME environment variable.  We then use `libloading`\nto load a dynamic library and call its `init` function.  Then we sleep for\na bit and shut down the runtime again.\n\nIn the dynamic library `lib/src/lib.rs` `init()` we spawn an async which logs\n`+++ Inside dylib async +++`.  Note that we are calling the runtime we get\npassed in directly, not relying on the thread-local variables.\n\nThere's lots of other logging to show the process, too.\n\n## Single-threaded\n\nRun in single-threaded mode with:\n\n`$ RUNTIME=single cargo run`\n\nOutput:\n\n```\nRunning in single mode\nRunning dylib init()\nInside dylib init()\nFinished dylib init()\nReturned from dylib init()\n--- Inside main async 1 ---\n+++ Inside dylib async +++\n--- Inside main async 2 ---\nShutting down\nDone!\n```\n\nNotice that all the asyncs happen after initialisation (when it goes to sleep),\nand both the async's in main.rs (`---`) and the one in the library (`+++`)\nare run.\n\n## Multi-threaded\n\nRun in multi-threaded mode with:\n\n`$ cargo run`\n\nOutput:\n\n```\nRunning in multi mode\n--- Inside main async 1 ---\nRunning dylib init()\nInside dylib init()\nFinished dylib init()\nReturned from dylib init()\nShutting down\nDone!\n```\n\nNotice that the first async in main.rs (`--- 1`) happens immediately (in a worker\nthread), but neither the one in the library (`+++`) or the one in main after it\n(`--- 2`) are run.\n\n## Why?\n\nI suspect that although we are explicitly passing and using the runtime, the\nmulti-threaded runtime uses some other static data which is not encompassed\nby it, and the dylib has a different version.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsandtreader%2Frust-tokio-dylib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsandtreader%2Frust-tokio-dylib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsandtreader%2Frust-tokio-dylib/lists"}