{"id":44917809,"url":"https://github.com/qpliu/repostm","last_synced_at":"2026-02-18T02:36:35.862Z","repository":{"id":57601232,"uuid":"81775528","full_name":"qpliu/repostm","owner":"qpliu","description":"repostm is a low-performance software transactional memory implementation for Go","archived":false,"fork":false,"pushed_at":"2017-03-02T22:26:51.000Z","size":26,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-06-20T03:33:38.169Z","etag":null,"topics":["go","stm"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/qpliu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-13T02:17:33.000Z","updated_at":"2019-10-05T03:06:00.000Z","dependencies_parsed_at":"2022-09-26T20:00:32.899Z","dependency_job_id":null,"html_url":"https://github.com/qpliu/repostm","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/qpliu/repostm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qpliu%2Frepostm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qpliu%2Frepostm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qpliu%2Frepostm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qpliu%2Frepostm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/qpliu","download_url":"https://codeload.github.com/qpliu/repostm/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qpliu%2Frepostm/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29566410,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-18T00:47:08.760Z","status":"online","status_checked_at":"2026-02-18T02:00:09.468Z","response_time":162,"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":["go","stm"],"created_at":"2026-02-18T02:36:35.800Z","updated_at":"2026-02-18T02:36:35.857Z","avatar_url":"https://github.com/qpliu.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"repostm is a low-performance software transactional memory (STM) implementation\nin Go, made primarily as a learning experience and an exploration into modeling\nan STM implementation after version control systems such as CVS, Subversion, or\nPerforce.\n\n[![GoDoc](https://godoc.org/github.com/qpliu/repostm?status.svg)](https://godoc.org/github.com/qpliu/repostm)\n[![Build Status](https://travis-ci.org/qpliu/repostm.svg?branch=master)](https://travis-ci.org/qpliu/repostm)\n\n# Implementation\n\nThis STM implementation stores data as slices of bytes, which are copied out on\nreads, and copied in on commits.  Hence, low-performance.\n\nData is encoded into byte slices and decoded from byte slices using\n`encoding/gob`.\n\n# Example\n\nExample of a concurrent producer and consumers, where each consumer will take\nno more than 25% of the current total produced.\n\n```go\nfunc ExampleProducerConsumers() {\n\trepo := repostm.New()\n\tvar wg sync.WaitGroup\n\n\tallocationPercentage := 25\n\tallocationCap := 100\n\tconsumerCount := 5\n\tproductionCap := 600\n\n\ttotalHandle := repo.Add(0)\n\tavailableHandle := repo.Add(0)\n\tallocationHandles := make([]repostm.Handle, consumerCount)\n\tfor i := range allocationHandles {\n\t\tallocationHandles[i] = repo.Add(0)\n\t}\n\n\tconsumer := func(allocationHandle repostm.Handle) {\n\t\tdefer wg.Done()\n\t\ttotal := totalHandle.Checkout()\n\t\tavailable := availableHandle.Checkout()\n\t\tallocation := allocationHandle.Checkout()\n\t\tfor allocation.Value.(int) \u003c allocationCap {\n\t\t\trepo.Atomically(func() error {\n\t\t\t\tcurrentCap := allocationPercentage * total.Value.(int) / 100\n\t\t\t\tif currentCap \u003e allocationCap {\n\t\t\t\t\tcurrentCap = allocationCap\n\t\t\t\t}\n\t\t\t\tif allocation.Value.(int) \u003e= currentCap {\n\t\t\t\t\treturn ErrRetryAfterCommit\n\t\t\t\t}\n\t\t\t\ttake := currentCap - allocation.Value.(int)\n\t\t\t\tif take \u003e available.Value.(int) {\n\t\t\t\t\ttake = available.Value.(int)\n\t\t\t\t}\n\t\t\t\tif take \u003e 0 {\n\t\t\t\t\tavailable.Value = available.Value.(int) - take\n\t\t\t\t\tallocation.Value = allocation.Value.(int) + take\n\t\t\t\t\treturn nil\n\t\t\t\t} else if currentCap \u003c allocationCap {\n\t\t\t\t\treturn ErrRetryAfterCommit\n\t\t\t\t} else {\n\t\t\t\t\treturn nil\n\t\t\t\t}\n\t\t\t}, total, available, allocation)\n\t\t}\n\t}\n\n\tfor _, allocationHandle := range allocationHandles {\n\t\twg.Add(1)\n\t\tgo consumer(allocationHandle)\n\t}\n\n\tcheck := func(total, available *repostm.Memory, allocations []*repostm.Memory) {\n\t\trepo.Update(append([]*repostm.Memory{total, available}, allocations...)...)\n\t\tif total.Value.(int) \u003c available.Value.(int) {\n\t\t\tfmt.Printf(\"total %d \u003c available %d\\n\", total.Value, available.Value)\n\t\t}\n\t\tallocationTotal := 0\n\t\tfor i, allocation := range allocations {\n\t\t\tallocationTotal += allocation.Value.(int)\n\t\t\tif total.Value.(int)*allocationPercentage/100 \u003c allocation.Value.(int) {\n\t\t\t\tfmt.Printf(\"%d%% of total %d \u003c allocation[%d] %d\\n\", allocationPercentage, total.Value, i, allocation.Value)\n\t\t\t}\n\t\t}\n\t\tif total.Value.(int) != available.Value.(int)+allocationTotal {\n\t\t\tfmt.Printf(\"total %d != available %d + allocations %d\\n\", total.Value, available.Value, allocationTotal)\n\t\t}\n\t}\n\n\tproducer := func() {\n\t\tdefer wg.Done()\n\t\ttotal := totalHandle.Checkout()\n\t\tavailable := availableHandle.Checkout()\n\t\tallocations := make([]*repostm.Memory, len(allocationHandles))\n\t\tfor i, allocationHandle := range allocationHandles {\n\t\t\tallocations[i] = allocationHandle.Checkout()\n\t\t}\n\t\tfor total.Value.(int) \u003c productionCap {\n\t\t\trepo.Atomically(func() error {\n\t\t\t\ttotal.Value = total.Value.(int) + 1\n\t\t\t\tavailable.Value = available.Value.(int) + 1\n\t\t\t\treturn nil\n\t\t\t}, total, available)\n\t\t\tcheck(total, available, allocations)\n\t\t}\n\t}\n\n\twg.Add(1)\n\tgo producer()\n\twg.Wait()\n\n\ttotal := totalHandle.Checkout()\n\tavailable := availableHandle.Checkout()\n\tallocations := make([]*repostm.Memory, len(allocationHandles))\n\tfor i, allocationHandle := range allocationHandles {\n\t\tallocations[i] = allocationHandle.Checkout()\n\t}\n\tcheck(total, available, allocations)\n\t// Output:\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqpliu%2Frepostm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fqpliu%2Frepostm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqpliu%2Frepostm/lists"}