CSE 8B Lecture 14: More multi-threading/ Synchonization
Document Summary
Synchronization yield() let other threads run if there are threads running sleep() will not run at all for a certain amount of time join() waits for calling thread to die. I have two threads t1 and t2 t1. join() means that the main thread will stop running and wait for t1 thread to finish t2 thread is unaffected and is still running in parallel with t1. Runnable is the interface to implement for making a thread. Override run method called when you (cid:862)start(cid:863) a thread. Os decides which thread has priority over which leads to random threads running unpredictably. Single core: threads can be swapped out at any time. Called context switch: no way of knowing when this might happen. Multiple cores: each core gets temp copy, both could read array[0], but either could write over it. 2 threads with same code running in parallel for(int i = 0; i < 3; i++) {