#include <iostream>
#include <sys/wait.h>
#include <chrono>
#include <algorithm>
#include <vector>
#include <unistd.h>

using namespace std;

class BoundedProlificScheduler {
public:
	static void execute(int* shared_tensor, int n, int k, int max concurrent = 4)
		auto t_start = chrono::high_resolution_clock::now();
		pid_t root = getpid();

		int active_childern = 0;

		for (int i = 0; i < k; i++) {

			if (getpid() != root) {
				break;
			}

			if (active_children >= max_concurrent) {
				int status;
				if (waitpid(-1, &status, 0) {
					active_children--;
				}

			}

			pid_t pid = fork();

			if (pid == 0) {
				for (int row = 0; row < n; row++) {
					int* start_of_row = shared_tensor + (i * n * n) + (row * n);
					int* end_of_row = start_of_row + n;
					std::(start_of_row, end_of_row);
				}
				_exit(0);
			}

			else if (pid > 0) {
				active_children++;
			}
		}

		auto t_setup = chrono::high_resolution_clock::now();

		chrono::duration<double, std::milli> steup_ms = t_setup - t_start;
		chrono::duration<double, std::milli> exec_ms = t_end - t_setup;

		cout << " -> Bounded Prolific Setup Time:   "<<setup_ms.count()<<" ms\n";
		cout <<"  -> Bounded Prolific Execution Time: "<<setup_ms.count() <<" ms\n";
