Topics:[[BR]] * Common pitfalls.[[BR]] * Current patterns.[[BR]] Those are the areas where we have some threading:[[BR]] * WebWorkers[[BR]] * FileAPI[[BR]] * Database (IconDatabase)[[BR]] * Compositor (Chromium specific)[[BR]] * Audio API[[BR]] WebWorkers (david_levin):[[BR]] * Mostly uses queue of tasks to pass messages between threads[[BR]] * Also some template magic to do the boiler plate code for message handling[[BR]] Compositor[[BR]] * Another good pattern[[BR]] * Very specific to this code[[BR]] * Have to do a lot of explicit copies of some data structure (String...)[[BR]] * Common data structure are not designed to be shared (mainly String agian)[[BR]] Audio API[[BR]] * They share the nodes between threads[[BR]] * Had had to create a new sharing model[[BR]] * The high priority audio thread is the one destroying the nodes[[BR]] * Not sure it should be generalized as it uses background threads' priority to solve some of the lifetime issues[[BR]] Current situation:[[BR]] * Sharing is bad as most objects are not designed to be shared[[BR]] * Strings for example are not shareable through threads (for performance)[[BR]] * Locking also is difficult to get right[[BR]] * Keep things isolated between threads![[BR]] * Don't do sharing! Difficult bugs too![[BR]] * Lots of copies involved to avoid sharing![[BR]] * Currently to be called back on the main thread, we use a Timer that is expensive and we need to keep some state.[[BR]] * Some dispatching API for running a task on this specific thread[[BR]] * XHR, File, IconDB all go back to the main thread[[BR]] * SQLDB has either to handle mainThread or another thread.[[BR]] * Ping-ponging easy to get wrong, you would need some object to handle that![[BR]] * Example is the DB where you don't need to send a CleanUp task when the thread is dead.[[BR]] * Future patterns: http://trac.webkit.org/wiki/ThreadCommunication [[BR]] Why not a templated cross-shared String?[[BR]] * Problem with performance![[BR]] * There is some mitigation already (semi efficient implementation for long String that avoid copying)[[BR]] Why not develop a push API for GraphicsContext?[[BR]] Issues[[BR]] * WebWorker complex because the lifetimes of both thread are independent[[BR]] Proposal (see link)[[BR]] * Template magic to match the API (like this is a String or something else)[[BR]] * Currently using raw pointers so we will need to Decorate them[[BR]] * Lifetime to be determined by the 'originated' thread[[BR]] * At some point, share code of Tasks, MessageQueues... in a common implementation somehow[[BR]] * Moving to a dispatch type model (thread pool, etc.) -- proposal (ap?, jchaffraix?).[[BR]] Somebody (sorry I did not take his name) called this: SystemWorldThread[[BR]] * Some threading cannot be moved to that (Audio...)[[BR]] * Some problem with some models[[BR]] * Maybe need some models[[BR]] * Game engines push the Audio to its own thread, the rest uses ThreadPools[[BR]] * Maybe not a size-fits-all solutions[[BR]] * Lots of values in having common Task[[BR]] * jchaffraix needs to sync with Ap about an API for that.[[BR]] Current work (https://bugs.webkit.org/show_bug.cgi?id=43903):[[BR]] * Parallelize SVG filters[[BR]] * Nice performance improvements[[BR]] * Also implemented a first API inspired by OpenMP[[BR]] * However there are others libraries / API available for multi-threading[[BR]] * What to parallelize.[[BR]] Not treated.