Beispiel #1
0
int main(int argc, char *argv[]) {

  printf("I am: %d\n", (int) getpid());

  pid_t pid = fork();
  srand((int) pid);

  if (pid < 0) {
    perror("Fork failed!\n");
  }
  else if (pid == 0) {
    printf("I am the child process with pid: %d, doing some work:\n", (int) getpid());
    doSomeWork("child");
    printf("child exiting...\n");
    exit(42);
  }
  // must be the parent
    printf("I am the parent process with pid: %d, and waiting for child: %d\n", (int) getpid(), pid);
    sleep(10);
    doSomeWork("parent");
    int status = 0;
    pid_t child_pid = wait(&status);
    printf("parent knows child %d finished with status: %d\n", (int)child_pid, WEXITSTATUS(status));

  return 0;

}
Beispiel #2
0
int main () {
    pid_t proccessId = getpid();
    printf("I am : %d \n",proccessId);
    sleep(2);


    pid_t pid  = fork();
    srand((int)pid);

    printf("Fork returned: %d \n",(int)pid);

    if(pid < 0) {
        perror("Fork Failed !!");
    }

    if (pid == 0) {
        printf("I am child with pid: %d\n",(int)getpid());
        doSomeWork("CHILD");
        exit(42);
    } else if (pid > 0) {
        printf("I am parrent  and waiting child to end:\n");
        sleep(30);
        doSomeWork("PARENT");
        int status = 0;
        pid_t child_PID = wait(&status);

        printf("Parent Know child %d finished with status %d...|\n",(int) child_PID,status);
        int child_return_value = WEXITSTATUS(status);
        printf(" \n Return value was -> %d \n",child_return_value);
    }


    return 0;
}
Beispiel #3
0
static void doSomeWork(double * a,int low, int high)
{
  if (high-low>300) {
    int mid=(high+low)>>1;
    cilk_spawn doSomeWork(a,low,mid);
    doSomeWork(a,mid,high);
    cilk_sync;
  } else {
void* threadInit(void *p){
    int *returnValue = (int*)p;
    try{
        doSomeWork(pthread_self(), *returnValue);
    }
    catch(ThreadExitException ex){
        ex.doThreadExit();
    }
    return 0;
}
void TunnelRenderer::StreamSource::onBufferAvailable(size_t index) {
    CHECK_LT(index, mBuffers.size());

    {
        Mutex::Autolock autoLock(mLock);
        mIndicesAvailable.push_back(index);
    }

    doSomeWork();
}