doc/COROUTINE_MANAGEMENT

Wed, 15 Jul 2009 10:39:10 -0400

author
Thomas Harning Jr <harningt@gmail.com>
date
Wed, 15 Jul 2009 10:39:10 -0400
changeset 64
dd47dbe85bec
parent 39
a0a7f7ebca3f
permissions
-rw-r--r--

Merge branch 'v0.2'

39
a0a7f7ebca3f Relocated the COROUTINE_MANAGEMENT document...
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
1 Due to the issue w/ self-resuming threads and crashing out threads,
a0a7f7ebca3f Relocated the COROUTINE_MANAGEMENT document...
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
2 a management system needs to be in place.
a0a7f7ebca3f Relocated the COROUTINE_MANAGEMENT document...
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
3
a0a7f7ebca3f Relocated the COROUTINE_MANAGEMENT document...
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
4 Example thread system:
a0a7f7ebca3f Relocated the COROUTINE_MANAGEMENT document...
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
5
a0a7f7ebca3f Relocated the COROUTINE_MANAGEMENT document...
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
6 MAIN
a0a7f7ebca3f Relocated the COROUTINE_MANAGEMENT document...
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
7 EVENT_LOOP --------running---
a0a7f7ebca3f Relocated the COROUTINE_MANAGEMENT document...
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
8 WAITING ON READ
a0a7f7ebca3f Relocated the COROUTINE_MANAGEMENT document...
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
9 WAITING ON WRITE
a0a7f7ebca3f Relocated the COROUTINE_MANAGEMENT document...
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
10 WAITING ON CONNECT
a0a7f7ebca3f Relocated the COROUTINE_MANAGEMENT document...
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
11
a0a7f7ebca3f Relocated the COROUTINE_MANAGEMENT document...
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
12
a0a7f7ebca3f Relocated the COROUTINE_MANAGEMENT document...
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
13 Since main and the other 'waiting' threads are yielded, it is unsafe to call things arbitrarily on them
a0a7f7ebca3f Relocated the COROUTINE_MANAGEMENT document...
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
14 or resume them from themselves...
a0a7f7ebca3f Relocated the COROUTINE_MANAGEMENT document...
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
15 However the EVENT_LOOP one is running and thus can execute the callbacks (which can resume the threads)
a0a7f7ebca3f Relocated the COROUTINE_MANAGEMENT document...
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
16 Each of the 'waiting' events are attached to an event and contain a pointer, this pointer can be setup to point
a0a7f7ebca3f Relocated the COROUTINE_MANAGEMENT document...
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
17 to a per event_base item which will be updated w/ the lua_State of whatever calls EVENT_LOOP...
a0a7f7ebca3f Relocated the COROUTINE_MANAGEMENT document...
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
18 this will guarantee that the thread will be resumed from the currently running EVENT_LOOP
a0a7f7ebca3f Relocated the COROUTINE_MANAGEMENT document...
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
19
a0a7f7ebca3f Relocated the COROUTINE_MANAGEMENT document...
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
20
a0a7f7ebca3f Relocated the COROUTINE_MANAGEMENT document...
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
21 Other system that's more complicated and less likely:
a0a7f7ebca3f Relocated the COROUTINE_MANAGEMENT document...
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
22
a0a7f7ebca3f Relocated the COROUTINE_MANAGEMENT document...
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
23 MAIN
a0a7f7ebca3f Relocated the COROUTINE_MANAGEMENT document...
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
24 EVENT_LOOP a -----running---
a0a7f7ebca3f Relocated the COROUTINE_MANAGEMENT document...
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
25
a0a7f7ebca3f Relocated the COROUTINE_MANAGEMENT document...
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
26 WAITING ON READ a
a0a7f7ebca3f Relocated the COROUTINE_MANAGEMENT document...
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
27 WAITING ON WRITE a
a0a7f7ebca3f Relocated the COROUTINE_MANAGEMENT document...
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
28
a0a7f7ebca3f Relocated the COROUTINE_MANAGEMENT document...
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
29 EVENT_LOOP b ----yielded
a0a7f7ebca3f Relocated the COROUTINE_MANAGEMENT document...
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
30 WAITING ON READ b
a0a7f7ebca3f Relocated the COROUTINE_MANAGEMENT document...
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
31
a0a7f7ebca3f Relocated the COROUTINE_MANAGEMENT document...
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
32
a0a7f7ebca3f Relocated the COROUTINE_MANAGEMENT document...
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
33 Since there can only be one event_loop running per event_base, you do not have to worry about
a0a7f7ebca3f Relocated the COROUTINE_MANAGEMENT document...
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
34 cross-pollination of the different waits...
a0a7f7ebca3f Relocated the COROUTINE_MANAGEMENT document...
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
35
a0a7f7ebca3f Relocated the COROUTINE_MANAGEMENT document...
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
36 NOTES:
a0a7f7ebca3f Relocated the COROUTINE_MANAGEMENT document...
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
37 If the event_loop thread goes away... then the waiting coroutines will have no way to get back...
a0a7f7ebca3f Relocated the COROUTINE_MANAGEMENT document...
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
38 though in this case, they are dead in the water anyways.. until a new event_loop starts...
a0a7f7ebca3f Relocated the COROUTINE_MANAGEMENT document...
Thomas Harning Jr <harningt@gmail.com>
parents:
diff changeset
39 in which case the lua_State references has been updated...

mercurial