The meaning of parallel is not that of parallel processing. I simply mean that if algorithms A and B are represented by the two sequence of operations (a_1, a_2, ...) and (b_1, b_2, ...), then the executed sequence of operations is (a_1, b_1, a_2, b_2, ...). It is not compulsory to be strictly 1 operation from A followed by 1 operation of B. This number may vary. Nonetheless, this should work on systems with only one thread of execution (without built-in parallelism).
The "merged" algorithm that is derived should terminate its execution when either A or B terminates.

The two functions A and B share all their input data, but they wont perform any write operation upon them.

How could I implement it in C++?

## All 3 Replies

I implemented something like that (I think) many years ago with MS-DOS 6.X. It was a series of functions that performed context stack switching so that there could be any number of "threads". Unlike modern-day MS-Windows or *nix, the program would switch contexts only when requested by the currently running thread. So instead of running threads like you described -- A_1 B_1 A-2 B_2 etc. it might run something like A-1 A-2 A-3 A-4 B-1 B-2 A-5 A-6 B-3 B-4 B-5 etc.

Well are the operations in your code. represented by a_1 , a_2, Different functions alltogether and is there anyway that we could represent a particular sub-process with a time constraint. If So you could always, Try a Shortest Time Notation which compares 2 stacks and looks to see which operation could be performed as the fastest.

However it might be, its quite hard for me as a beginer in the language to understand the Paralleled Dynamism as I mostly go through Sequential Programming.

What I need is not that complex, but I don't know the way to implement it. In other words, I would like to emulate the parallel execution with two threads in one. How to do it?

Note: The solution of executing the function A, and then function B doesn't work. I want them to run concurrently in one thread.
I hope it doesn't sound absurd. The reason for such a need is that such a "parallelism" will ensure the termination of combined algorithm.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.