Yeah, I figured that out yesterday... my theory is that we're supposed to store the jump buffers in a shared memory region with shmget() and related functions... but I gave up on fork() and switched to threads. The professor never mentioned threads in class, but he discussed fork and jumps at some length; whenever anyone asked him about context switching and child processes it was always discussed in the context of fork/jmp. However, he noted that we could do the implementation as we saw fit and, if it worked, he wouldn't dock us.
Ultimately, the assignment is to write a small realtime executive that runs three tasks that we also have to program and takes a small amount of user input, but while the rest of my group works on the data structures and functions, I'm learning UNIX programming and trying to create multiple processes or threads and have them communicate and switch between them (it doesn't need to be preemptive).
I finally gave up last night, though, and bit the bullet and learned the basics of the
pthread library. It was a million times easier than trying to beat fork(), longjmp(), set_sp(), and shmget() into submission all at once... I'm trying to tweak things now so I can control switching between threads. Inter-thread communication seems to be working well, though I'm not sure how to prevent, for example, a thread printing some output in the middle of the parent's output. For example, if the parent has
pthread_cancel(Thread's ID);
cout << "Parent";
in its code, and a thread has
cout << "Thread";
sometimes, because I don't have much control over thread scheduling, it prints
ParThreadent
Which really isn't any good. I don't think it will be a major problem, but if I can do something about it I'd like to
