Skip to content

Instantly share code, notes, and snippets.

View sreeram780's full-sized avatar

SreenivasulaReddy sreeram780

View GitHub Profile
@sreeram780
sreeram780 / Semaphore.swift
Created March 1, 2018 05:58 — forked from jhanzo/Semaphore.swift
Quick overview about semaphores
//In iOS, Grand Central Dispatch brings some utilities for using asynchronous tasks
//Among all functionalities, there is Semaphore which is an old school theory thought by Djikstra
//More info here : https://en.wikipedia.org/wiki/Semaphore_(programming)
//Semaphores give a control access to a common resource through concurrent tasks (done in other threads)
//NB 1: in iOS, all UI jobs has to be done ONLY in main thread, otherwise a fatal error occurs
//NB 2: before using semaphore in iOS you should always wonder if dispatch_group is not enough
//NB 3: for doing an async task in your playground you have to use semaphore concept or at least this two kinds of methods :
// XCPlaygroundPage.currentPage.needsIndefiniteExecution = true
// XCPlaygroundPage.currentPage.finishExecution()