Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
I suggest you get the task switching code to dump all the task data when it switches, that showed a few problems in my code. Also try just 2 tasks, and depending on how your thread switching works, maybe try just 1 task (my code would still do a thread switch even if the thread to be switched to was the thread already running).
if the problem can be reproduced in BOCHS, i suggest you let the test running with "trace-on". That should provide you a exhaustive list of executed instructions eventually ending with the faulty one.
I suspect either your print("xxx") isn't thread-safe (e.g. if you have general variables and no locking...) or that your switching process doesn't restore the stack as expected and results in a slowly growing (and eventually getting wrong) stack.
Of course, knowing eIP and CR3 for the fault will help you to figure out where things goes wrong ...
Pype.Clicker wrote:
I suspect either your print("xxx") isn't thread-safe (e.g. if you have general variables and no locking...) or that your switching process doesn't restore the stack as expected and results in a slowly growing (and eventually getting wrong) stack.
Maybe my print("**") isn't thread-safe.....
here is my print():
it is indeed not thread safe in the sense that accesses to global pointer "vp" are not protected in any way, yet all updates of vp should be "atomic" and thus there shouldn't be possible (assuming decent compiler) to trash that pointer...
The worse you will get with that code is "missing" characters (as some of them might be "replaced" by characters printed by another thread)
So probably your problem is more with stack. I suggest you print your "esp" address in the loops (or track its value somehow). If everything works fine, the loop should always keep the same ESP for the sme thread.