Пример #1
0
/*
  function to be called
  base_pointer          the base pointer to a element
  number_of_elements    the number of elements to sort
  width                 offset of an element
  compar_func           the comparison function
//*/
void quicksort(void* base_pointer
	       , size_t number_of_elements
	       , size_t width
	       , int (*compar_func)(const void*, const void *))
{
  static int number_of_processors = -1;

  /*
    get the number of processors and do some performance related settings
  //*/
  if(number_of_processors == -1){
    // get the number of processors (= cpu's)
    number_of_processors = sysconf( _SC_NPROCESSORS_ONLN);
    
    // lwp for each cpu
    if((number_of_processors > 1) && (pthread_getconcurrency() < number_of_processors))
      pthread_setconcurrency(number_of_processors);
    
    // thread count not to exceed THR_PER_LWP per lwp
    threads_avail = (number_of_processors == 1) ? 0 : (number_of_processors * THR_PER_LWP);
  }

  /*
    set up the sorting arguments
  //*/
  sort_args_t sort_args;
  sort_args.sortargs_base = base_pointer;
  sort_args.sortargs_number_of_elements = number_of_elements;
  sort_args.sortargs_width = width;
  sort_args.sortargs_compar_func = compar_func;

  // start sorting
  _quicksort(&sort_args);
}
Пример #2
0
int main(int argc, char** argv)
{
	grid_size = GRID_SIZE;
	nthreads = NTHREADS;	
	if(argc>=2){
	nthreads = atoi(argv[1]);
	grid_size = atoi(argv[2]);
	}
   	omp_set_num_threads(nthreads);
   
   /*#pragma omp parallel
   {
		cout<<"Hello"<<endl;
   }*/
   //int i=0;
   /*matrix<double > temp;
   temp.resize(10,10);
   #pragma omp parallel for
   	for(int i=0;i<10;i++)
		for(int j=0;j<10;j++)
			cout<<temp(i,j);
   */
  
   glutInit(&argc, argv);
   initMain ();
   int i=pthread_getconcurrency();

   char windowName[]="   Liquid_Simulator-LevelSet+Surface" ;
   openGlutWindow(windowName);

   glutMainLoop();
   
   return 0; 
}
Пример #3
0
///////////////////////////////////////////////////////////////////////
//main, setup and execution of environment
int main(int argc, char **argv) {

	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
	glutInitWindowPosition(100,100);
	glutInitWindowSize(568,320);
	glutCreateWindow("Computer Graphics");

	glutDisplayFunc(renderScene);
	glutIdleFunc(renderScene);
	glutReshapeFunc(changeSize);
	glutKeyboardFunc(processNormalKeys);

	glutMouseFunc(mouseClick);
	glutMotionFunc(mouseMotion);

	glEnable(GL_DEPTH_TEST);
	glClearColor(0.0,0.0,0.0,1.0);

	glewInit();
	if (GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader)
		printf("Ready for GLSL\n");
	else {
		printf("No GLSL support\n");
		exit(1);
	}

	if (glewIsSupported("GL_VERSION_3_3"))
		printf("Ready for OpenGL 3.3\n");
	else {
		printf("OpenGL 3.3 not supported\n");
		exit(1);
	}
	if (GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader && GL_EXT_geometry_shader4)
		printf("Ready for GLSL - vertex, fragment, and geometry units\n");
	else {
		printf("Not totally ready :( \n");
		exit(1);
	}

	if (GL_ARB_fragment_program && GL_ARB_vertex_program && GL_EXT_framebuffer_object)
		printf("Ready for FrameBuffer\n");
	else {
		printf("Not totally ready :( \n");
		exit(1);
	}


	initialize();
#ifdef __linux__
  int i=pthread_getconcurrency();
#endif
	setShaders();

	glutMainLoop();
	return EXIT_SUCCESS;
}
Пример #4
0
int
do_test (void)
{
    int c = pthread_getconcurrency ();
    if (c != 0)
    {
        puts ("initial concurrencylevel wrong");
        exit (1);
    }

    if (pthread_setconcurrency (1) != 0)
    {
        puts ("setconcurrency failed");
        exit (1);
    }

    c = pthread_getconcurrency ();
    if (c != 1)
    {
        puts ("getconcurrency didn't return the value previous set");
        exit (1);
    }

    int e = pthread_setconcurrency (-1);
    if (e == 0)
    {
        puts ("setconcurrency of negative value didn't failed");
        exit (1);
    }
    if (e != EINVAL)
    {
        puts ("setconcurrency didn't return EINVAL for negative value");
        exit (1);
    }

    c = pthread_getconcurrency ();
    if (c != 1)
    {
        puts ("invalid getconcurrency changed level");
        exit (1);
    }

    return 0;
}
Пример #5
0
int
ldap_pvt_thread_get_concurrency(void)
{
#ifdef HAVE_PTHREAD_GETCONCURRENCY
	return pthread_getconcurrency();
#elif defined(HAVE_THR_GETCONCURRENCY)
	return thr_getconcurrency();
#else
	return 0;
#endif
}
Пример #6
0
int main(int argc, char** argv)
{
   glutInit(&argc, argv);
   init ();
   int i=pthread_getconcurrency();

   char windowName[]="   Liquid_Simulator-LevelSet+Surface" ;
   openGlutWindow(windowName);

   glutMainLoop();
   return 0;
}
Пример #7
0
void bbcp_Thread_MT(int mtval)
   {
#ifdef SUN
#ifndef SUN6 // Ranch version added this #ifndef SUN6
    int rc, oldmt = pthread_getconcurrency(), newmt = mtval;

    while(mtval)
         if ((rc = pthread_setconcurrency(mtval)) && rc == EAGAIN) mtval--;
            else break;

    DEBUG("MT set rc=" <<rc <<" omt=" <<oldmt <<" rmt=" <<newmt <<" nmt=" <<mtval);
#endif
#endif
   }
Пример #8
0
void *POSIX_Init(
  void *argument
)
{
  int  sc;

  TEST_BEGIN();

  puts( "Init: pthread_getconcurrency - initial value of 0" );
  sc = pthread_getconcurrency();
  rtems_test_assert( sc == 0 );

  puts( "Init: pthread_setconcurrency - set value to 2" );
  sc = pthread_setconcurrency( 2 );
  rtems_test_assert( sc == 0 );

  puts( "Init: pthread_getconcurrency - confirm new value of 2" );
  sc = pthread_getconcurrency();
  rtems_test_assert( sc == 2 );

  TEST_END();
  rtems_test_exit(0);
}
Пример #9
0
int main(int argc, char **argv) {
    int basura = pthread_getconcurrency();

    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA|GLUT_DEPTH);
    glutInitWindowSize(rHeight,rWidth);
    glutCreateWindow("Bloc 3");
    init();
    glEnable(GL_DEPTH_TEST);
    glutDisplayFunc(refresh);
    glutReshapeFunc(resize);
    glutMouseFunc(mouseClicked);
    glutMotionFunc(mouseMoved);
    glutKeyboardFunc(teclado);
    glutIdleFunc(update);
    glutMainLoop();
    return 0;
}
Пример #10
0
static int print_thread_attr(pthread_attr_t *attr)
{
    if (attr == NULL)
    {
        return THREAD_ATTR_FAILED;
    }

    int detach_state = 0;
    int ret = 0;
    char *stack_addr = NULL;
    size_t stack_size = 0;
    size_t guard_size = 0;

    ret = pthread_attr_getdetachstate(attr, &detach_state);
    if (detach_state == PTHREAD_CREATE_JOINABLE)
    {
        printf("Thread detach state: JOINABLE\n");
    }
    else if (detach_state == PTHREAD_CREATE_DETACHED)
    {
        printf("Thread detach state: DETACHED\n");
    }

    ret = pthread_attr_getstack(attr, (void**)&stack_addr, &stack_size);
    printf("stack_addr:%p, stack_size:%zd\n", stack_addr, stack_size);

    ret = pthread_attr_getstacksize(attr, &stack_size);
    printf("stack size:%#x\n", stack_size);

    ret = pthread_attr_getguardsize(attr, &guard_size);
    printf("guard size:%#x\n", guard_size);


    ret = pthread_getconcurrency();
    printf("concurrency is %d\n", ret);
    
    return THREAD_ATTR_OK;
}
Пример #11
0
int main(int argc, char** argv)
{
	grid_size = GRID_SIZE;
	nthreads = NTHREADS;	
	if(argc>=2){
	nthreads = atoi(argv[1]);
	grid_size = atoi(argv[2]);
	}
 	omp_set_num_threads(nthreads);
	struct timeval tt1, tt2;
	initMain();
	int i=pthread_getconcurrency();
	int it=0;
	int ni= 0;
	while(ni++<NO_OF_ITERATIONS){
		gettimeofday(&tt1, NULL);
		animate();
		gettimeofday(&tt2, NULL);
		int milliSeconds = (tt2.tv_sec - tt1.tv_sec) * 1000 + (tt2.tv_usec - tt1.tv_usec)/1000;
		cout<<"Iteration "<<it<<" : "<<milliSeconds<<"ms"<<endl<<endl;
		it++;
	}
	return 0;
}
Пример #12
0
void X11OpenGLWindow::enableOpenGL()
{

    m_data->m_glc = glXCreateContext(m_data->m_dpy, m_data->m_vi, NULL, GL_TRUE);
    glXMakeCurrent(m_data->m_dpy, m_data->m_win, m_data->m_glc);

    const GLubyte* ven = glGetString(GL_VENDOR);
    printf("GL_VENDOR=%s\n", ven);
    const GLubyte* ren = glGetString(GL_RENDERER);
    printf("GL_RENDERER=%s\n",ren);
    const GLubyte* ver = glGetString(GL_VERSION);
    printf("GL_VERSION=%s\n", ver);
    const GLubyte* sl = glGetString(GL_SHADING_LANGUAGE_VERSION);
    printf("GL_SHADING_LANGUAGE_VERSION=%s\n", sl);

//Access pthreads as a workaround for a bug in Linux/Ubuntu
//See https://bugs.launchpad.net/ubuntu/+source/nvidia-graphics-drivers-319/+bug/1248642

    int i=pthread_getconcurrency();
    printf("pthread_getconcurrency()=%d\n",i);

//    const GLubyte* ext = glGetString(GL_EXTENSIONS);
//    printf("GL_EXTENSIONS=%s\n", ext);
}
Пример #13
0
int main(int argc, char* argv[])
{
  printf("Program %s Begin\n", argv[0]);
  struct tms begintime;
  clock_t begreal = times(&begintime);

  struct sigaction act, oact;
  sigemptyset(&act.sa_mask);
  act.sa_flags = SA_SIGINFO;
  act.sa_sigaction = sigaction_handle_fun;
  sigaction(SIGTERM, &act, &oact);


  pthread_t pthreadid = pthread_self();
  printf("pthreadid:%u\n", pthreadid);


  pthread_mutex_init (&(gcounter.m_mutex), NULL);
  gcounter.m_cout = 0;

  pthread_attr_t pthreadattr;
  pthread_attr_init(&pthreadattr);
  size_t pthreadstacksize;

  pthread_attr_getstacksize(&pthreadattr, &pthreadstacksize);
  printf("pthreadstacksize:%u\n", pthreadstacksize);
  printf("pthread_getconcurrency:%d\n", pthread_getconcurrency());

  pthread_t newpthreadid;
  char* charg = "000 pass to pthread";
  int pcreateret = pthread_create(&newpthreadid, NULL, pthread_fun0, charg);
  if(pcreateret != 0)
  {
    perror("pthread_create error");
  }
  else
  {
    printf("newpthreadid:%u\n", newpthreadid);
  }

  pthread_t newpthreadid1;
  char* charg1 = "100 pass to pthread";
  int pcreateret1 = pthread_create(&newpthreadid1, NULL, pthread_fun1, charg);
  if(pcreateret1 != 0)
  {
    perror("pthread_create error");
  }
  else
  {
    printf("newpthreadid:%u\n", newpthreadid1);
  }

  void* pret;
  pthread_join(newpthreadid, &pret);
  pthread_join(newpthreadid1, &pret);

  char chcwdbuf[100];
  if(getcwd (chcwdbuf, 100) == NULL)
  {
    perror("getcwd error");
  }
  else
  {
    printf("getcwd %s\n", chcwdbuf);
  }

  printf("input characters:\n");
  int c;
  while( (c = getc(stdin)) != EOF)
  {
    if(putc(c, stdout) == EOF)
    {
      perror("putc error");
    }
  }


  time_t t = time(NULL);
  struct tm* localtm = localtime(&t);
  printf("Time:%s\n", asctime(localtm));

  printf("getlogin:%s\n", getlogin());


  atexit(atexit_fun1);
  atexit(atexit_fun2);

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

  pid_t pid;

  if( (pid = fork()) < 0)
  {
    perror("fork error\n");
  }
  else if(pid == 0)
  {
    printf("great this is child process created by fork \n");
    printf("getpid():%d\n", getpid());
    printf("getppid():%d\n", getppid());
    printf("getpgrp():%d\n", getpgrp());
  }
  else
  {
    printf("parent process is here.\n");

  }

  /* extern char** environ; */

  /* char** env = environ; */
  /* while(*env) */
  /* { */
  /* ++env; */
  /* printf("%s\n", *env); */
  /* } */



  /* while(environ[]) */
  /* { */
  /* printf(""); */
  /* } */

  /* while(!GbStop) */
  /* 	/\* while(1)  //C99 define true C89 didn't define *\/ */
  /* { */

  /* } */
  struct tms endtime;
  clock_t endreal = times(&endtime);

  printf("real:%f\n"
         "user:%f\n"
         "sys:%f\n",
         (float)(endreal-begreal)/CLOCKS_PER_SEC, (float)(endtime.tms_utime-begintime.tms_utime)/CLOCKS_PER_SEC, (float)(endtime.tms_stime-begintime.tms_stime)/CLOCKS_PER_SEC );

  return 0;
}
Пример #14
0
int Thread::concurrency_priv()                  { return pthread_getconcurrency(); }
Пример #15
0
void junk() {
  int i;
  i=pthread_getconcurrency();
};
Пример #16
0
int main()
{
    int8_t           x;
    pid_t            pid;
    pthread_t        tid;
    pthread_key_t    tkey;
    char             *s, c;
    struct timespec  ns = {.tv_nsec=0};
    unsigned int     i, nr_fun, failed;
    int              err, ret[2]= {0,0}, stat;
    pthread_rwlock_t tlock = PTHREAD_RWLOCK_INITIALIZER;
    const char      *function[] = {
        "pthread_create",
        "pthread_cancel",
        "pthread_once",
        "pthread_setspecific",
        "pthread_key_delete",
        "pthread_join",
        "pthread_atfork",
        "pthread_sigmask",
        "pthread_setschedprio",
        "pthread_setconcurrency",
        "pthread_detach",
        "pthread_key_create",
        "pthread_rwlock_unlock",
        "pthread_kill",
        //"pthread_equal",
    };
    struct {
        unsigned int
        kill:1,
             wait:1;
    } error, no_error = {.wait=0};
    struct sigaction act = {.sa_handler=handle, .sa_flags=SA_NODEFER};


    failed = 0;
    for (i=0;  i < (nr_fun=sizeof(function)/sizeof(*function));  ++i) {
        pipe(pfd);
        memset(&error, 0, sizeof(error));
        if (!(pid = fork())) {
            close(pfd[0]);
            blocked = 0; //wrappers set it to 1 after saving env
            sigaction(SIGTERM, &act, NULL);
            sigaction(SIGABRT, &act, NULL);
            pthread_create(&tid, NULL, thread, block);
            switch (i) {
            case 0:
                err = wrap_pthread_create(&tid, NULL, thread, NULL);
                break;
            case 1:
                err = wrap_pthread_cancel(tid);
                break;
            case 2:
                err = wrap_pthread_once(
                (pthread_once_t []) {
                    PTHREAD_ONCE_INIT
                },
                block
                      );
                break;
            case 3:
                if (!pthread_key_create(&tkey, NULL)) {
                    err = wrap_pthread_setspecific(tkey, NULL);
                    pthread_key_delete(tkey);
                } else
                    err = -3;
                break;
            case 4:
                //key creation(inicialization) done in the wrapper:
                err = wrap_pthread_key_delete(tkey);
                break;
            case 5:
                err = wrap_pthread_join(tid, NULL);
                break;
#ifndef GLIBC
            case 6:
                err = wrap_pthread_atfork(NULL, NULL, NULL);
                break;
#endif
            case 7:
                err = wrap_pthread_sigmask(SIG_UNBLOCK, NULL, NULL);
                break;
#ifndef MUSL
            case 8:
                err = wrap_pthread_setschedprio(
                          tid,
                          sched_get_priority_min(sched_getscheduler(0))
                      );
                break;
#endif
            case 9:
                err = wrap_pthread_setconcurrency(pthread_getconcurrency());
                break;
            case 10:
                err = wrap_pthread_detach(tid);
                break;
            case 11:
                //key deletion done in the wrapper:
                err = wrap_pthread_key_create(&tkey, NULL);
                break;
            case 12:
                if (!pthread_rwlock_init(&tlock, NULL)) {
                    err = wrap_pthread_rwlock_unlock(&tlock);
                    pthread_rwlock_destroy(&tlock);
                }
                else
                    err = -2;
                break;
            case 13:
                err = wrap_pthread_kill(tid, 0);
                break;
            /*
            case 14:
                err = wrap_pthread_equal(tid, tid);
            break;
            */
            default:
                blocked = 0;
                close(pfd[1]);
                err = -2;
                break;
            }
            return err;
        }

        if (!pid) {
            fprintf(stdout, "BUG: child i=%d escaped!\n", i);
            exit(0); //exit/contain child
        } else if (pid == -1) {
            close(pfd[1]);
            close(pfd[0]);
            fprintf(stderr,
                    "A call to fork() nr %d/%d yielded -1 (errno=%s)!\n",
                    i+1, nr_fun, (s = e_name(errno))
                   );
            free(s);
            failed += 1;
        } else {
            close(pfd[1]);
            read(pfd[0], &c, 1); //wait for the child to become ready
            close(pfd[0]);

            //Send SIGABRT to child in delays of <NANOSLEEP_MAX/100,0> microsec:
            ns.tv_nsec = NANOSLEEP_MAX;
            while(
                (ret[0] = kill(pid, SIGABRT)) == 0
                && (ret[1] = waitpid(pid, &stat, WNOHANG)) == 0
                && (ns.tv_nsec -= 100)
            )
                nanosleep(&ns, NULL);
            //let child's function out of its loop/blocked state
            kill(pid, SIGTERM);
            if (!ns.tv_nsec)
                waitpid(pid, &stat, 0);

            //Process errors:
            s = e_name(errno);
            error.kill = (ret[0] != 0);
            error.wait = (ret[1] != 0 && ret[1] != pid);
            if (memcmp(&error, &no_error, sizeof(error))) {
                ++failed;
                if (error.kill)
                    fprintf(stderr,
                            "A call to kill() returned %d, errno=%s\n",
                            ret[0], s
                           );
                if (error.wait)
                    fprintf(stderr,
                            "A call to waitpid() returned %d, errno=%s\n",
                            ret[1], s
                           );
            } else if (WIFEXITED(stat)) {
                if ((x = WEXITSTATUS(stat))) {
                    ++failed;
                    if (x == -2)
                        fprintf(stderr,
                                "%s() and/or its dependencies missing!\n",
                                function[i]
                               );
                    else if (x == -3)
                        fprintf(stderr,
                                "%s() was not tested - its dependency failed\n",
                                function[i]
                               );
                    else if (x) {
                        free(s);
                        s = e_name(x);
                        fprintf(stderr, "%s() returned %s\n", function[i], s);
                    }
                }
            } else {
                fprintf(stderr, "%s()'s host process crashed!\n", function[i]);
                if (WIFSIGNALED(stat))
                    fprintf(stderr,
                            "\tTerminating signal: %d\n",
                            (int)WTERMSIG(stat)
                           );
            }
            free(s);
        }
    }
    return failed;
}

/**
 ** Signal handler. Upon receiving the first SIGTERM it unsets blocked, longjmps
 ** Otherwise - on another signal or if blocked is unset - it simply returns
 **/
static void handle(int sig)
{
    if (sig == SIGTERM) {
        if(blocked) {
            blocked = 0;
            longjmp(env, 1);
        }
        //else {printf("BUG: Misplaced SIGTERM!\n");} //-----
    }
}
///waits for blocked to be unset by a signal[!] via the signal handler, returns
static void block(void)
{
    while(blocked)
        sched_yield(); //can't use pause() - handle() doesn't return on SIGTERM
    sleep(3);
    printf("exit block()\n");//---
}

/**
 ** Establishes the function passed to it as a thread cancellation handler and
 ** calls it. Thus, if the executing thread is canceled, the said function will
 ** still have to be executed before the thread is terminated.
 ** \param fun a void* cast of (void (*)()) or NULL (only return)
 **/
static void* thread(void *fun)
{
    if (fun != NULL) {
        pthread_cleanup_push(fun, NULL);
        ((void (*)())fun)();
        pthread_cleanup_pop(0);
    }
    return NULL;
}

///<Wrappers start here: They take the same arguments as the functions they
///<call but install the SIGTERM handler and optionally loop until it's received

static int wrap_pthread_create(pthread_t *restrict thread,
                               const pthread_attr_t *restrict attr,
                               void *(*start_routine)(void*),
                               void *restrict arg)
{
    WRAP_START
    while (!err)
        err = pthread_create(thread, attr, start_routine, arg);
    WRAP_END
}
static int wrap_pthread_cancel(pthread_t thread)
{
    WRAP_START
    err = pthread_cancel(thread);
    WRAP_END
}
Пример #17
0
void X11OpenGLWindow::enableOpenGL()
{


    if (forceOpenGL3)
    {
 // Get the default screen's GLX extension list
  const char *glxExts = glXQueryExtensionsString( m_data->m_dpy,
                                                  DefaultScreen( m_data->m_dpy ) );

  // NOTE: It is not necessary to create or make current to a context before
  // calling glXGetProcAddressARB, unless we dynamically load OpenGL/GLX/X11

  glXCreateContextAttribsARBProc glXCreateContextAttribsARB = 0;
  glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc)
           glXGetProcAddressARB( (const GLubyte *) "glXCreateContextAttribsARB" );

  GLXContext ctx = 0;

  // Install an X error handler so the application won't exit if GL 3.0
  // context allocation fails.
  //
  // Note this error handler is global.  All display connections in all threads
  // of a process use the same error handler, so be sure to guard against other
  // threads issuing X commands while this code is running.
  ctxErrorOccurred = false;
  int (*oldHandler)(Display*, XErrorEvent*) =
         MyXSetErrorHandler(&ctxErrorHandler);

  // Check for the GLX_ARB_create_context extension string and the function.
  // If either is not present, use GLX 1.3 context creation method.
  if ( !isExtensionSupported( glxExts, "GLX_ARB_create_context" ) ||
       !glXCreateContextAttribsARB )
  {
    printf( "glXCreateContextAttribsARB() not found"
            " ... using old-style GLX context\n" );
    ctx = glXCreateNewContext( m_data->m_dpy, m_data->m_bestFbc, GLX_RGBA_TYPE, 0, True );
  }

  // If it does, try to get a GL 3.0 context!
  else
  {
	 int context_attribs[] = {
          GLX_CONTEXT_MAJOR_VERSION_ARB ,3,
          GLX_CONTEXT_MINOR_VERSION_ARB, 2,
          GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB,
          GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB,None
     };
/*
    int context_attribs[] =
      {
        GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
        GLX_CONTEXT_MINOR_VERSION_ARB, 2,

        //GLX_CONTEXT_FLAGS_ARB        , GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
        None
      };
*/
    printf( "Creating context\n" );
    ctx = glXCreateContextAttribsARB( m_data->m_dpy, m_data->m_bestFbc, 0,
                                      True, context_attribs );

    // Sync to ensure any errors generated are processed.
    MyXSync( m_data->m_dpy, False );
    if ( !ctxErrorOccurred && ctx )
      printf( "Created GL 3.0 context\n" );
    else
    {
      // Couldn't create GL 3.0 context.  Fall back to old-style 2.x context.
      // When a context version below 3.0 is requested, implementations will
      // return the newest context version compatible with OpenGL versions less
      // than version 3.0.
      // GLX_CONTEXT_MAJOR_VERSION_ARB = 1
      context_attribs[1] = 1;
      // GLX_CONTEXT_MINOR_VERSION_ARB = 0
      context_attribs[3] = 0;

      ctxErrorOccurred = false;

      printf( "Failed to create GL 3.0 context"
              " ... using old-style GLX context\n" );
      ctx = glXCreateContextAttribsARB( m_data->m_dpy, m_data->m_bestFbc, 0,
                                        True, context_attribs );
    }
  }

  // Sync to ensure any errors generated are processed.
  MyXSync( m_data->m_dpy, False );

  // Restore the original error handler
  MyXSetErrorHandler( oldHandler );

  if ( ctxErrorOccurred || !ctx )
  {
    printf( "Failed to create an OpenGL context\n" );
    exit(1);
  }

  // Verifying that context is a direct context
  if ( ! glXIsDirect ( m_data->m_dpy, ctx ) )
  {
    printf( "Indirect GLX rendering context obtained\n" );
  }
  else
  {
    printf( "Direct GLX rendering context obtained\n" );
  }

  printf( "Making context current\n" );
  glXMakeCurrent( m_data->m_dpy, m_data->m_win, ctx );
  m_data->m_glc = ctx;

    } else
    {
        m_data->m_glc = glXCreateContext(m_data->m_dpy, m_data->m_vi, NULL, GL_TRUE);
        glXMakeCurrent(m_data->m_dpy, m_data->m_win, m_data->m_glc);
    }

#ifdef GLEW_INIT_OPENGL11_FUNCTIONS
{
	GLboolean res = glewOpenGL11Init();
	if (res==0)
		{
			printf("glewOpenGL11Init OK!\n");
		} else
			{
				printf("ERROR: glewOpenGL11Init failed, exiting!\n");
				exit(0);
			}
}

#endif //GLEW_INIT_OPENGL11_FUNCTIONS

    const GLubyte* ven = glGetString(GL_VENDOR);
    printf("GL_VENDOR=%s\n", ven);

    const GLubyte* ren = glGetString(GL_RENDERER);
    printf("GL_RENDERER=%s\n",ren);
    const GLubyte* ver = glGetString(GL_VERSION);
    printf("GL_VERSION=%s\n", ver);
    const GLubyte* sl = glGetString(GL_SHADING_LANGUAGE_VERSION);
    printf("GL_SHADING_LANGUAGE_VERSION=%s\n", sl);

//Access pthreads as a workaround for a bug in Linux/Ubuntu
//See https://bugs.launchpad.net/ubuntu/+source/nvidia-graphics-drivers-319/+bug/1248642

	int i=pthread_getconcurrency();
        printf("pthread_getconcurrency()=%d\n",i);

//    const GLubyte* ext = glGetString(GL_EXTENSIONS);
//    printf("GL_EXTENSIONS=%s\n", ext);
}