> Gesendet: Donnerstag, 15. Juli 2021 um 21:21 Uhr > Von: "Alexander Tormasov via users" <[email protected]> > An: "Genode users mailing list" <[email protected]> > Cc: "Alexander Tormasov" <[email protected]> > Betreff: Re: How to switch thread stack between threads? > > >> > >> So, to fix it I need during switch of context to non-local thread > >> (setcontext() or even longjump() functions) I should update these data to > >> current running stack. > > user level switching is only valid within the same thread. The only way to > > do this is to do a local > > user level switch to a user level thread that immediately blocks the os > > level thread and wakes the os level > > thread, that is blocked in the same procedure and corresponds to the target > > user level thread. At wakeup that > > user level thread, which was blocked at the os level, reads the target user > > level thread and makes a local > > user level switch to it. > > The Mutex on which the user level threads blocks (at least its address) > > needs to be part of the context. > > probably I give a wrong picture of operations I did understand you the first time around. But I have to disappoint you. What you want is IMPOSSIBLE! At least in genode. Because you can't create such a context. > 1. I run arbitrary function with stack associated with first thread Every stack implies (is bound to) an os level thread. > 2. I copy current context using getcontext and store it somewhere You must store a pointer to an os level object that holds the os level thread (mutex is fine) with the context to be able to later resume in the correct context. > 3. I stop doing function from 1, by switching to another function/stack > associated with thread 1 That is possible. > 4. after some time I create a new os thread and run some code inside it > 5. then inside 2 thread I take old context from 2 above and perform > setcontext from inside 2 thread to replace current function with state in the > thread to the first one You can not use context from 2 in another thread. Alternatively you can reconstruct the call chain from the first thread in the second thread with Duffs Device (https://en.wikipedia.org/wiki/Duff's_device#See_also) And then you can construct a mirror context, which is the first context but in the second thread. > > So, I don’t need mutexes and wait for something - I have a time gap between > suspend of function in os 1 and it continuation on thread 2. The mutexes have another purpose. They regulate the os level threads when user level threads yield. > during continuation I already switched to thread 2… > just need to associate old stack with it (it contains state of function/stack > from 1) > > > _______________________________________________ > Genode users mailing list > [email protected] > https://lists.genode.org/listinfo/users
_______________________________________________ Genode users mailing list [email protected] https://lists.genode.org/listinfo/users
