Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merge] pthreads early exit #100

Open
cesarjp opened this issue Mar 23, 2020 · 3 comments
Open

[Merge] pthreads early exit #100

cesarjp opened this issue Mar 23, 2020 · 3 comments

Comments

@cesarjp
Copy link
Collaborator

cesarjp commented Mar 23, 2020

The following pthread test exits early. It should print out the number '10'. Based on the output, the process never migrates back to node 0.

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include "migrate.h"

#define NUM_THREADS 2

int data[NUM_THREADS];

void *do_it(void *t)
{
  int ret = 0;
  int i = (int)t;

  data[i] = 10;

  pthread_exit (&ret);
}

int
main (int argc, char *argv[])
{
  int i;
  pthread_t threads[NUM_THREADS];
  
  migrate(0, NULL, NULL);

  for (i = 0; i < NUM_THREADS; i++)
    {
      pthread_create(&threads[i], NULL, do_it, (void *)i);
    }

  for (i = 0; i < NUM_THREADS; i++)
    {
      int status = 0;
      pthread_join (threads[i], &status);
    }

  migrate(1, NULL, NULL);

  printf ("%d\n", data[0]);

  return data[0];
}

Here is the output:

popcorn@x86:~$ ./pthread_test
[ 28.879191] ####### MIGRATE [633] to 1
[ 29.019960] EXITED [633] local / 0xa00
[ 29.023048] TERMINATE [238/1] with 0x2560

@bxatnarf
Copy link
Collaborator

@cesarjp Is the output you posted based on starting execution on node 0 or node 1?
I see that your example first calls migrate(0, NULL, NULL) which sort of implies it shouldn't begin on node 0. But if I start from node 1, I am seeing a whole different set of issues, so I just want to double check.

@cesarjp
Copy link
Collaborator Author

cesarjp commented Mar 30, 2020

@bxatnarf, I should have been more clear. I was testing multiple combinations of the test. One version launched from the x86 host (which is node 0) and another version that launched from the arm node (node 1).

Here's the code that corresponds to this output:

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include "migrate.h"

#define N 50
#define NUM_THREADS 2

int data[NUM_THREADS];

void *do_it(void *t)
{
  int ret = 0;
  int i = (int)t;

  data[i] = 10;

  pthread_exit (&ret);
}

int
main (int argc, char *argv[])
{
  int i;
  pthread_t threads[NUM_THREADS];

  migrate(1, NULL, NULL);
  for (i = 0; i < NUM_THREADS; i++)
    {
      pthread_create(&threads[i], NULL, do_it, (void *)i);
    }

  for (i = 0; i < NUM_THREADS; i++)
    {
      int status = 0;
      pthread_join (threads[i], &status);
    }

  migrate(0, NULL, NULL);

  printf ("%d\n", data[0]);

  return data[0];
}

@bxatnarf
Copy link
Collaborator

If the first example starts execution from host 0, then we should not expect to see it to printf anything since printf is called after it migrates to host 1. If we execute the code in #100 (comment) from host 0 then we should see the printf since it migrates to 0 before the printf.
@cesarjp on which host do you execute this second example? to get the output you pasted in the original question?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants