Running code concurrently -- Running code while running other code

suggest change

Say you want to perform in action (in this case, logging “Foo”), while doing something else (logging “Bar”). Normally, if you don’t use concurrency, one of these actions is going to be fully executed, and the other run will run only after it’s completely finished. But with concurrency, you can make both actions run at the same time:

dispatch_async(dispatch_queue_create("Foo", DISPATCH_QUEUE_CONCURRENT), ^{

for (int i = 0; i < 100; i++) { NSLog(@“Foo”); usleep(100000); }

});

for (int i = 0; i < 100; i++) {

NSLog(@“Bar”); usleep(50000);

}

This will log “Foo” 100 times, pausing for 100ms each time it logs, but it will do all this on a separate thread. While Foo is being logged, “Bar” will also be logged in 50ms intervals, at the same time. You should ideally see an output with “Foo”s and “Bars” mixed together

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Concurrency:
* Running code concurrently -- Running code while running other code

Table Of Contents
12 UIView
15 UIColor
20 Concurrency
26 UIImage
28 CALayer
30 NSDate
40 iBeacon
49 NSTimer
79 NSURL
87 AWS SDK
96 NSData
101 Segues
104 EventKit
105 NSBundle
106 SiriKit
111 StoreKit
117 3D Touch
119 Keychain
122 Block
141 AirDrop
144 UISlider
145 Carthage
146 HealthKit
151 plist
157 MVVM
164 UIPhoenix
166 Simulator
168 NSArray
169 OpenGL
175 Core Data
179 MyLayout
180 UIFont
189 Security
200 Codable