Problem with setjmp(probably). please help

I have a problem with my project. It should run some processes simultaneously, using interrupts, but i get throw out of borland c after the first part of every process was terminated and the longjmp tries to restore the first process. I think setjmp loads some unwanted values into the jmp_buf variable.
I posted some files which may contain the error. If necessary i can post the rest to.
Sorry for my english and for the romanian variable names.

____________________This is the file in which the problem occurs_______________

#include "RTexec.h"
#include "mydefs.h"

#include <setjmp.h>
#include <dos.h>
#include <stdlib.h>
#include <alloc.h>
#include <dos.h>

#define CLK 0x08
#define OLD_CLK 0x60

void interrupt(*RTexec::oldfunc)(...);
int RTexec::proces_activ;
jmp_buf RTexec::retEnv;
int RTexec::nr_procese;
RTprocess * RTexec::tabela_procese[4];

RTexec::RTexec(myDefs::info_init_proces * initT, int nrp){

int dimTotalStack;
nr_procese = nrp;

for(int i = 0;i<=nr_procese;i++){
tabela_procese[i] = new RTprocess(initT[i]);
dimTotalStack += tabela_procese[i]->dim_stiva;
if(tabela_procese[i]->stare == myDefs::ACTIV) proces_activ = i;
}

char * totalStack = (char *)malloc(dimTotalStack);
char * freeStack = (char *)malloc(coreleft()-dimTotalStack);

for(i = 0; i<=nr_procese; i++){
tabela_procese[i]->env->j_ss = FP_SEG(totalStack);
tabela_procese[i]->env->j_sp = FP_OFF(totalStack+(i)*tabela_procese[i]->dim_stiva);
}

free(freeStack);
}


RTexec::~RTexec(void){}

void interrupt RTexec::Planificator(...){

geninterrupt(OLD_CLK);
if(tabela_procese[proces_activ]->stare == myDefs::ACTIV)
tabela_procese[proces_activ]->stare = myDefs::PREGATIT;
int oldProcActiv = proces_activ;


int count = proces_activ;
int found = 0;
do{
count++;
if(count >= nr_procese) count = 0;
if(tabela_procese[count]->stare == myDefs::PREGATIT){
tabela_procese[count]->stare = myDefs::ACTIV;
proces_activ = count;
found = 1;
}
}while (found == 0);

if ( setjmp( tabela_procese[oldProcActiv]->env ))
return;
else
longjmp( tabela_procese[proces_activ]->env , 1 );

}

void RTexec::procNULL(){

while(1) Planificator();
}

void RTexec::DoIt(){

oldfunc=getvect(CLK);
setvect(OLD_CLK, oldfunc);
setvect(CLK, Planificator);
procNULL();
}

void RTexec::Exit(){

// nr_procese--;
tabela_procese[proces_activ]->stare = myDefs::INEXISTENT;
if(nr_procese == 0){
setvect(CLK,oldfunc);
sleep(1);
exit(1);
}
else Planificator();
}

___________________________This is his header file____________________________

#ifndef RTEXEC_H_SEEN
#define RTEXEC_H_SEEN

#include "RTproces.h"

#include <setjmp.h>

class RTexec
{
static RTprocess * tabela_procese[4];
static int nr_procese;
static jmp_buf retEnv;
static void interrupt(*oldfunc)(...);
static int proces_activ;

public:
RTexec(myDefs::info_init_proces *, int);
~RTexec();
static void interrupt Planificator(...);
static void procNULL(); static void Exit();
static void DoIt();
static void Tile(int nr);
};
#endif

______________________This is the file containing the main()___________________

#include "RTexec.h"
#include "mydefs.h"

#include <stdio.h>
#include <conio.h>
#include <dos.h>

#define STACK 1200

void proc1(){
for(int i=0; i<=100;i++){
printf("proc1");
}
RTexec::Exit();
}

void proc2(){
for(int i=0; i<=100;i++){
printf("proc2");
}
RTexec::Exit();
}
void proc3(){
for(int i=0; i<=100;i++){
printf("proc3");
}
RTexec::Exit();
}
void proc4(){
for(int i=0; i<=100;i++){
printf("proc4");
}
RTexec::Exit();
}


myDefs::info_init_proces * initTable;

void initAllProcs(){

initTable[0].adresa_init = proc1;
initTable[0].nume_process = "Proces 1";
initTable[0].dim_stiva = STACK;
initTable[0].stare = myDefs::PREGATIT;

initTable[1].adresa_init = proc2;
initTable[1].nume_process = "Proces 2";
initTable[1].dim_stiva = STACK;
initTable[1].stare = myDefs::PREGATIT;

initTable[2].adresa_init = proc3;
initTable[2].nume_process = "Proces 3";
initTable[2].dim_stiva = STACK;
initTable[2].stare = myDefs::PREGATIT;

initTable[3].adresa_init = proc4;
initTable[3].nume_process = "Proces 4";
initTable[3].dim_stiva = STACK;
initTable[3].stare = myDefs::PREGATIT;

initTable[4].adresa_init = RTexec::procNULL;
initTable[4].nume_process = "Proces NULL";
initTable[4].dim_stiva = 1024;
initTable[4].stare = myDefs::ACTIV;

}


int main(){

clrscr();
initAllProcs();
RTexec* rte = new RTexec(initTable,4);
rte->DoIt();
return 0;
}
Topic archived. No new replies allowed.