Segfault joy: sharing memory between execution context
Posted in TVM scheduling on September 12th, 2011 by williaz – Be the first to commentTo create multiple TVMs I initialize multiple contexts in the wrapper (initially using pthreads). This presents many challenges because if I were to naively create four TVM, for example, I would have four independent runtimes and a single occam program would actually be run four times in parallel. To handle this the initial thought was to have certain pointers in each context point to the same thing as the original context. While doing this we decided to initialize the contexts as they are need, moving the creation of new contexts to within the scheduler so when something was added to the scheduling queue a new thread was created. Because thing are only added to the queue when parallel occam processes are created this prevents waist by not creating extra TVMs until they are needed.
Currently I have run into several problems in my attempts to do the above mentioned steps. The first issue is with getting the pointer in the context to point to the right thing. Currently I create one context and then every time a new context is created I set the pointers of the new context equal to those in the old context. While in theory this should work, I clearly have some implementation issue. The code which does this is below.
Because the code to create a context is in the wrapper but I am now creating new contexts in the scheduler the function for starting a context but be available. To handle this I created a new pointer in the context (which is available to everybody) which points to the function that needs to be called. However I am having similar trouble with this aspect of the code.
Example:
Where ea is an array of pointers to execution contexts (ea[0] reserved for firmware)
121 122 ea[1]->spawn_hook = ea[n]-> spawn_hook; 123 ea[1]->spawn_hook = run_multicore; 124
run_multicore is a function defined above these lines and spawn_hook is a function (pointer) defined in the execution context struct.
However if I print the value of the pointers they are different. I have a similar problem with int and other pointers within the context struct. But because the pointers being shared across contexts refer to dynamic location, for example as the queue changes state all the pointers must change, I need to be able to set and forget them and know that all contexts will be pointing to the right place at all times, which I thought was the whole point of pointers. This question may demonstrate my clear lack of understanding when it comes to the see language and any comments or thoughts people have are warmly welcomed.