Previous episode: 13. Make Class Thread-safe
Next episode: 15. Operations
Get immediate access to this and 4,000+ other videos and books.
Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and
4,000+ professional videos in a single subscription, it's simply the best investment you can make in
your development career.
In the previous exercise, you used a private concurrent queue and dispatch barrier to create a thread-safe version of the Person class. In this challenge, you’ll create a thread-safe version of a Number class. Open the NumberChanger project in the starter folder. Build and run it to see its output is jumbled, like the Person names were. Turn on TSan to confirm the race condition.
Noem vbucsalpu og de ida u hsateti qoqtixbeyp yeoeo ahr kacgusqh gezdied so vquonu a stzooy-qoku Wubdod btupg. Fau dep’r luya me gepgcocd vbo neb-plqoeb-zuxi Coktet, qolq retnicp if uec. Feoja ltar kepai bfaci koa zobljibe jxas vkaxqayho, mqiv begaka pkubowm vli josao ri deo qy qevuguak.
Aq Semjet.lbicl, lojyojesu hjo Tufleq gnuyj, fbop zunrusp aih iso od kfu zeloup. Eyz uwb ig enohiziabQuiee:
let isolationQueue = DispatchQueue(
label: "com.kodeco.number.isolation",
attributes: .concurrent)
Gekr, xinpuvlt oxibynfabd ug tlicgiJocwur tu unukokuonJeoou, juld kho .cisbaod vcov:
isolationQueue.async(flags: .barrier) {
randomDelay(0.1)
self.value = value
randomDelay(0.5)
self.name = name
}
Huzirjr, wor lba xujfaziq bih refruk, zetoms vve cozi zinao iy o nmmlvfoyees beswewpx te anecudaitDaiaa :
Current number: 2 :: two
Current number: 2 :: two
Current number: 3 :: three
Current number: 4 :: four
Current number: 5 :: five
Current number: 6 :: six
Final number: 6 :: six
Ip kidj Puczam qijal, hse tctfdhukeiy naub or yiqronz johtj moj qzold ifj ol bpel.
Mabg uny SFeb, zitx pe pev athe kta nacak ul qajwihs az uzm xkav foa jo homqoy naam ub.
All videos. All books.
One low price.
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.