Changes between Version 3 and Version 4 of ThreadCommunication
- Timestamp:
- Apr 14, 2011, 10:20:03 AM (14 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
ThreadCommunication
v3 v4 12 12 '''Use cases''' 13 13 14 1. An object exist on one thread. It wants to create an object on another thread and then have a number of calls happen between these two objects.15 This oneis a superset of other potential cases including fire and forget.[[BR]]14 1. An object exist on one thread. It wants to create an object on another thread and be able to call methods on it. 15 This is a superset of other potential cases including fire and forget.[[BR]] 16 16 17 2. An object wants to be able to allow another thread to be able to call its methods.[[BR]] 17 18 18 Issue: Should this use case be broken up into several?[[BR]] 19 3. A function wants to call a method on another thread and wait until it is done. Allowing callbacks resulting from that to run in the web worker thread. 20 This does look suspiciously like a nested message loop with a filter which many people regard as evil. The only reason to allow this capability is for synchronous calls from javascript to call to the main thread to get some work done and act like a synchronous call but there may be callbacks (e.g. when doing a sync xhr call.) Theoretically, the javascript engine could roll up its state into a closure and we could avoid the nested message loop but that capability doesn't exist in the engines that we deal with and would be very expensive to add to them.[[BR]] 19 21 20 21 2. A web worker thread wants to call a function on another thread and wait until it is done. Allowing callbacks resulting from that to run in the web worker thread. 22 This does look suspiciously like a nested message loop with a filter which many people regard as evil. The only reason to allow this capability is for synchronous calls from javascript to call to the main thread to get some work done and act like a synchronous call but there may be callbacks (e.g. when doing a sync xhr call.) Theoretically, the javascript engine could roll up its state into a closure and we could avoid the nested message loop but that capability doesn't exist in the engines that we deal with and would be very expensive to add to them.[[BR]] 22 The framework should track the dependencies to check for possible deadlocks.[[BR]] 23 23 24 24 … … 34 34 '''Proposed code samples for use cases''' 35 35 36 TBD: Here is where some code will go to show what these use cases look like. 36 Case 1: Create an object on another thread:[[BR]] 37 38 {{{ 39 // Creates a proxy and initializes a target object on a given message loop. 40 RefPtr<TypeName::Proxy> proxy = TypeName::createProxy(otherMessageLoop, constructorArg1, constructorArg2, ...); 41 42 // Calls method on the object on the other message loop. This does not need to wait for some signal that the object has been created. 43 proxy->invoke(&TypeName::method, arg1, arg2, ...); 44 }}} 45 46 Case 2: Allow an object on another thread to do callbacks:[[BR]] 47 48 {{{ 49 // getProxy is a method in the current object which returns its proxy. The proxy may be used with invoke like these examples. 50 proxy->invoke(&TypeName::method, arg1, getProxy(), arg3, ...); 51 }}} 37 52 38 53 54 Case 3: A thread wants to call a function on another thread and wait until it is done. 55 56 TBD