views:

42

answers:

3

I have a C++ program that allows a user to single step through processor instructions as a processor simulator emulates a MIPS processor. The problem is that, at least in my testing stages, I need to initialize ~2^32 integers to 0xDEADBEEF. I do this at start-up. It isn't extremely important that this happens completely before I start "single stepping". Is it possible for the initialization function to occur in parallel to the rest of the program so that, it will eventually finish but as it progresses I can still single step? How would one do this?

A: 

You could run your initialization function in a separate thread, however you will need to create a locking mechanism on memory to ensure that the memory in-use by the simulated application isn't over-written by the init function.

Jim
A: 

It depends. A separate process means that what happens to its runtime environment has no affect on other processes' runtime environments. If your initialization needs to affect the runtime environment of the main process, then a separate process would be tricky. A separate thread would be better, as it can affect the runtime environment of the process that started the thread. You can just have the thread run at initialization and do its thing while the rest of the program goes on as normal. This may or may not include the need for semaphores (Or other similar synchronization methods); it depends on whether or not mutual exclusion exists.

In short, yes it's possible. How you accomplish this though depends on how you do this "single stepping."

Jesse J
+1  A: 

Instead of initializing a huge amount of memory up front, could you initialize it in smaller chunks when the emulator brings them into existence for the program being run?

Mark B