{"id":34583540,"url":"https://github.com/dabevlohn/lock-or-not","last_synced_at":"2026-05-30T05:31:10.621Z","repository":{"id":328669526,"uuid":"1106085799","full_name":"dabevlohn/lock-or-not","owner":"dabevlohn","description":"Rust workshop repo","archived":false,"fork":false,"pushed_at":"2025-12-23T15:09:40.000Z","size":27,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-12-25T05:15:11.897Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dabevlohn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-11-28T15:54:18.000Z","updated_at":"2025-12-23T16:35:54.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/dabevlohn/lock-or-not","commit_stats":null,"previous_names":["dabevlohn/lock-or-not"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dabevlohn/lock-or-not","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dabevlohn%2Flock-or-not","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dabevlohn%2Flock-or-not/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dabevlohn%2Flock-or-not/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dabevlohn%2Flock-or-not/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dabevlohn","download_url":"https://codeload.github.com/dabevlohn/lock-or-not/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dabevlohn%2Flock-or-not/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33681809,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-30T02:00:06.278Z","response_time":92,"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-12-24T10:26:19.144Z","updated_at":"2026-05-30T05:31:10.615Z","avatar_url":"https://github.com/dabevlohn.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Mutex Code (main branch)\n\nThe mutex-based code demonstrates several classic concurrency design patterns adapted to Rust's ownership model:\n\n### **Producer-Consumer Pattern**\n\n- Multiple threads (`spawn_job`) act as **consumers** reading from shared `Arc\u003cMutex\u003cVec\u003cT\u003e\u003e\u003e`.\n- `main()` acts as **producer** calling `add()` after spawning.\n- Mutex serializes access to the shared vector, ensuring thread safety.\n\n\n### **Shared Mutable State Pattern**\n\n- `Arc\u003cMutex\u003cVec\u003cT\u003e\u003e\u003e` provides **shared ownership** (Arc) + **interior mutability** (Mutex).\n- Classic RAII-style resource guarding: lock scope ensures data consistency.\n\n\n### **Trait Object Polymorphism**\n\n- `Arc\u003cdyn Job + Send + Sync + 'static\u003e` enables **dynamic dispatch** for different job types (`Ji`, `Js`).\n- Follows **Strategy Pattern** — interchangeable behaviors (`run()`, `add()`) without changing client code.\n\n\n### **Thread Pool / Worker Pattern**\n\n- Vector of `JoinHandle`s collects spawned threads, waited on sequentially — basic **worker pool** precursor.\n\n\n## Lock-Free Code (lock-free branch)\n\nThe SegQueue version showcases advanced **lock-free programming patterns**:\n\n### **Lock-Free Producer-Consumer (MPMC Queue)**\n\n- `SegQueue` implements **Michael-Scott (MS) Queue** algorithm using **CAS (Compare-And-Swap)** atomics.\n- **Multi-Producer Multi-Consumer (MPMC)**: unlimited producers (`add()`) and consumers without blocking.\n- **Helping Pattern**: threads assist each other's failed CAS operations to ensure progress (lock-freedom).\n\n\n### **Atomic Reference Counting (Shared Ownership)**\n\n- `Arc\u003cSegQueue\u003cT\u003e\u003e` maintains **lock-free reference counting** for the queue itself.\n- No central lock — each `push()` uses segmented atomic operations.\n\n\n### **Non-Blocking Delegation**\n\n- Delegates **mutable operations** to the queue's internal lock-free linked list.\n- **Wait-Free** elements (bounded number of steps per operation) via segmented design.\n\n\n### **Trait Object + Lock-Free Integration**\n\n- Same **Strategy/Polymorphism** as mutex version, but now with **lock-free data structure**.\n- `Send + Sync + 'static` bounds ensure safe cross-thread delegation.\n\n\n## Key Differences in Patterns\n\n| Aspect | Mutex (Blocking) | SegQueue (Lock-Free) |\n| :-- | :-- | :-- |\n| **Synchronization** | Coarse-grained lock | Fine-grained atomics + CAS |\n| **Progress Guarantee** | Mutual exclusion | Lock-freedom (no deadlocks) |\n| **Scalability** | Poor (contention) | Excellent (no lock contention) |\n| **Complexity** | Simple RAII | Advanced CAS loops + helping |\n\n**Mutex**: Uses **Guarded Access Pattern** (simple, correct, scales poorly).\n**SegQueue**: Uses **Lock-Free Queue Pattern** (complex, performant, scales linearly).\n\nBoth leverage **Rust's ownership + traits** for type-safe polymorphism, but SegQueue demonstrates sophisticated **concurrent data structure design** avoiding traditional locking entirely.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdabevlohn%2Flock-or-not","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdabevlohn%2Flock-or-not","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdabevlohn%2Flock-or-not/lists"}