|
C O U R S E L E C T U R E Concurrency Challenges Notes taken on June 24, 2014 by Edward Tanguay |
prime reason for concurrency
leveraging advances in hardware and software
it's hard to buy a computing device that has just one core
today there are even quad-core Android phones
event driven architecture
for blocking operations, had to post on message queue, then handle it later on an event loop
used the reactor pattern
now operating system and middleware have better concurrency support
Android provides several concurrency frameworks which enable multiple threads to perform long-running computations in the background
this maps efficiently onto multiple cores
these background operations can block independently of the UI thread
using these frameworks effectively requires knowledge of concurrency patterns
e.g. worker thread pattern:
overlaps computation and communication mechanisms
background threads that download images can run in parallel with each other, and with a thread that interacts with the user
use the RenderScript framework
targeted at image processing, computational photography, or computer vision
even with one core, concurrency can be used to improve perceived response time
e.g. ensures that the user interface doesn't ignore input while other operations are running
accidental complexities
written in programs like C
low-level and error-prone data types
casting disable compile-time type checking, causes errors
some types are not compatible on other platforms, e.g. non-POSIX platforms
most operating systems today have these kinds of problems when low-level programming languages like C are used
developers use tools that aren't set up to handle concurrency
you need tools that enable you to drill down and look inside your software to figure out what is happening
the behavior you see in the debugger doesn't necessarily reflect the behavior in the actual software
scheduling and synchronization
the order and time that operations are performed
ensure that multiple concurrent threads don't simultaneously execute in criticial sections of a program at the same time
air traffic controllers share runway resource for mulitple planes
likewise, Android needs to synchronize access to the SQLite contact database
ensures that threads are given proper access to system resources
two or more competing actions are waiting for the other to finish and so neither ever do
need to be identified and removed
bugs that change their behavior when observed
you may use a debugger to step through one thread while other threads are running