int main (int argc, char *argv[]) { pthread_t h[NTHREADS]; pthread_create (&h[0], 0, thread_dlopen_func, 0); for (unsigned long i = 1; i < NTHREADS; i++) { pthread_create (&h[i], 0, thread_func, 0); } unsigned long pinDetached = false; TellPinToDetach(&pinDetached); while (!pinDetached) { sleep(2); } loop1 = false; loop2 = false; for (unsigned long i = 0; i < NTHREADS; i++) { pthread_join (h[i], 0); } printf("All threads exited. The test PASSED\n"); return 0; }
int main (int argc, char *argv[]) { pthread_t h[NTHREADS]; unsigned long fsBase = 0; int res = syscall(SYS_arch_prctl, ARCH_GET_FS, &fsBase); if (res != 0) { printf("SYS_arch_prctl failed with error: %s\n", strerror(errno)); return -1; } for (unsigned long i = 0; i < NTHREADS; i++) { pthread_create (&h[i], 0, thread_func, (void *)i); } /* * If the number of threads is big, some threads leave system call "clone" * while PIN is detached. This functionality is also tested here. */ TellPinToDetach(&pinDetached); void * result[NTHREADS]; for (unsigned long i = 0; i < NTHREADS; i++) { pthread_join (h[i], &(result[i])); } for (unsigned long i = 0; i < NTHREADS; i++) { if (result[i] != 0) { fprintf(stderr, "TEST FAILED\n"); return -1; } } unsigned long fsBaseAfterDetach = 0; res = syscall(SYS_arch_prctl, ARCH_GET_FS, &fsBaseAfterDetach); if (fsBase != fsBaseAfterDetach) { fprintf(stderr, "ERROR in the main thread: FS_BASE before detach 0x%lx; after detach 0x%lx\n", fsBase, fsBaseAfterDetach); return -1; } fprintf(stderr, "TEST PASSED\n"); return 0; }