{"id":16306194,"url":"https://github.com/gfx/swift-multithreading","last_synced_at":"2025-10-25T14:30:48.421Z","repository":{"id":18930768,"uuid":"22150180","full_name":"gfx/Swift-MultiThreading","owner":"gfx","description":"A demo code for synchronization in Swift","archived":false,"fork":false,"pushed_at":"2015-11-23T01:44:21.000Z","size":18,"stargazers_count":13,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-06T18:21:54.390Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://qiita.com/gfx/items/532f9f975de5a965c58a","language":"Swift","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/gfx.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}},"created_at":"2014-07-23T13:38:41.000Z","updated_at":"2018-11-12T17:11:07.000Z","dependencies_parsed_at":"2022-09-11T06:21:12.180Z","dependency_job_id":null,"html_url":"https://github.com/gfx/Swift-MultiThreading","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gfx%2FSwift-MultiThreading","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gfx%2FSwift-MultiThreading/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gfx%2FSwift-MultiThreading/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gfx%2FSwift-MultiThreading/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gfx","download_url":"https://codeload.github.com/gfx/Swift-MultiThreading/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238155504,"owners_count":19425727,"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","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":"2024-10-10T21:09:57.107Z","updated_at":"2025-10-25T14:30:48.148Z","avatar_url":"https://github.com/gfx.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Synchronization in Swift\n\nSwift has no synchornozation functionality in the language,\nbut Foundation framework is available to synchronize the code.\n\n## Use of `dispatch_sync()`\n\n```swift\nclass Foo {\n  var value = 0\n  let sync = dispatch_queue_create(\"\\(self.dynamicType).sync\", DISPATCH_QUEUE_SERIAL)\n\n  func incrementWithSerialQueue() {\n      dispatch_sync(sync) {\n          self.value += 1\n      }\n  }\n\n```\n\n## Use of `objc_sync_enter()` and `objc_sync_exit()`\n\n```swift\nclass AutoSync {\n    let object : AnyObject\n\n    init(_ obj : AnyObject) {\n        object = obj\n        objc_sync_enter(object)\n    }\n\n    deinit {\n        objc_sync_exit(object)\n    }\n}\n\nclass Foo {\n  var value = 0\n\n  func incrementWithObjcSync() {\n      let lock = AutoSync(self)\n      self.value += 1\n  }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgfx%2Fswift-multithreading","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgfx%2Fswift-multithreading","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgfx%2Fswift-multithreading/lists"}