From the course: Writing Secure Code in iOS by Infosec

Unlock this course with a free trial

Join today to access over 24,900 courses taught by industry experts.

Activity: Preventing race conditions

Activity: Preventing race conditions

- [Instructor] Interprocess communications. Activity: preventing race conditions. Open Swift Projects, open Course 5, open Preventing a Race Condition, and open the Playground. In our example, a user is going to try to withdraw money from two ATM automatic teller machines at the same time. In real life, I'm not sure how well that would work. Most ATMs these days lock the card and don't release them. But let's pretend that these are two older ATMs where you just slide the card in and out. The user has a starting balance of 1,200 and we create a struct ATM and we're going to use a tag to identify which ATM in the debug console we're talking about. We have a function to withdraw money and the value is of course an int and we'll use the tag and we'll print a message checking for sufficient funds. If the balance is greater than what they're trying to withdraw, this value, then we'll say balance is sufficient. Please wait while we're processing the withdrawal. And then we're going to…

Contents