I have a function which looks a bit like this:
bufferPtr = 0
    //code to examine for a known string
while (bufferPtr < Max_ptr)

I'm wanting to change the program so that I create 4 separate threads, each doing a 1/4 of the buffer, would this be possible?

So where bufferPtr is is 0 and max_ptr is the size of the buffer, each thread would have a startPtr and an endPtr respectively.

If so/not any ideas on the best way to implement it?

Thanks for any help in advance!
Let me just say that this is inconvenient. Looping into a variable is probably faster done in a single thread, than to create four threads and to wait for them all to begin and end. Because you will HAVE to wait for a thread's begin, and to wait for a thread's end.
The buffer is quite large and this process is being done a massive amount of times, processing in excess of 500gb of data.
The idea being that 4 threads simultaneously processing their section buffer is quicker was based on a multi-core system and the fact the program is currently maxing out a single core of the processor.
Much as I realise I will have to wait for all 4 threads to end, it still seems this might be quicker.
Last edited on
Yes, you can do it. What is stopping you? I guess I mean: What is the complication you are having in splitting this intro threads?
Sorry. So that was a good reason, just think about a thing: You will not be able to load 500gb of data into ram.
Anyways, you should have something like CreateThread or _beginthread (process.h) to begin a thread, prepare a struct of "common data" between threads and send the pointer as a LPVOID (void *) when beginning the thread, and once the first thread ended, call WaitForSingleObject for each Thread Handle that has been returned from CreateThread/_beginthread or WaitForMultipleObjects for a Thread Handle Array.
webjose: As I already have to code for working in a single thread, I was trying to figure how to take this and insert it into a threads, taking additional parameters to define the start and end points for each thread.
So basically so I could create the threads using a quarter of the buffer so
thread2(bufffersize/4, bufffersize/2)
thread3(bufffersize/2, bufffersize/ 4 * 3)
thread4(bufffersize/4 * 3, bufffersize)

Looking for how I would write the thread structure.

The buffer is only read and never written to so it should be ok to access from all threads rather than creating a copy right?
Well, I guess is pretty much the same algorithm for all threads, only processing different buffer addresses.

You can read and write to the buffer from all threads as long as the buffer addresses don't overlap.
Topic archived. No new replies allowed.