bool BaseSprocBase::runFunction(ThreadFuncF fThreadFunc, void *pThreadArg) { bool returnValue = true; Int32 rc = 0; _bInitialized = false; if(fThreadFunc != NULL) { _pThreadData[0] = (void *) fThreadFunc; _pThreadData[1] = pThreadArg; _pThreadData[2] = (void *) this; rc = sproc(BaseSprocBase::threadFunc, PR_SALL, (void *) _pThreadData); if(rc == -1) { SFATAL << "OSGSPB : sproc thread failed. Reason: " << strerror(errno) << std::endl; returnValue = false; } } else { SFATAL << "OSGSPB : no thread function given"; returnValue = false; } return returnValue; }
bool vrpn_Thread::go() { if (threadID != 0) { fprintf(stderr, "vrpn_Thread::go: already running\n"); return false; } #ifdef sgi if ((threadID=sproc( &threadFuncShell, PR_SALL, this ))== ((unsigned long)-1)) { perror("vrpn_Thread::go: sproc"); return false; } // Threads not defined for the CYGWIN environment yet... #elif defined(_WIN32) && !defined(__CYGWIN__) // pass in func, let it pick stack size, and arg to pass to thread if ((threadID=_beginthread( &threadFuncShell, 0, this )) == ((unsigned long)-1)) { perror("vrpn_Thread::go: _beginthread"); return false; } #else // Pthreads by default if (pthread_create(&threadID, NULL, &threadFuncShellPosix, this) != 0) { perror("vrpn_Thread::go:pthread_create: "); return false; } #endif return true; }
/* * Initialize the audio hardware. */ int sfxInit(char *audioDir, int numPorts) { int idx; char *str; if (audioDir != NULL) { str = strdup(audioDir); if (str) sfxAudioDir = str; } if (numPorts < 1) return SFX_ERR_NO_PORTS_AVAIL; if (numPorts > MAX_AUDIO_PORTS) numPorts = MAX_AUDIO_PORTS; (void) ALseterrorhandler(sfxSoundErrFunc); nAudioPorts = sfxOpenAudioPorts(audioPort, numPorts); if (nAudioPorts == 0) return SFX_ERR_NO_PORTS_AVAIL; if (nAudioPorts < 0) return SFX_ERR_NO_AUDIO_HW; (void) signal(SIGCHLD, sfxSoundDied); if (pipe(spigot) < 0 || (soundChild = sproc(sfxSoundHandler, PR_SADDR, audioPort)) < 0) { for (idx=0; idx < nAudioPorts; idx++) ALcloseport(audioPort[idx]); return SFX_ERR_NO_SPROC; } return nAudioPorts; }
main() { unsigned inh = PR_SADDR; sproc(f,inh); for (i=1; i<=10000000; i++) {;} printf("parent: buf is %d\n", buf); }
int SDL_SYS_CreateThread(SDL_Thread *thread, void *args) { /* Create the thread and go! */ if ( sproc(SDL_RunThread, PR_SALL, args) < 0 ) { SDL_SetError("Not enough resources to create thread"); return(-1); } return(0); }
wxThreadError wxThread::Create() { if (p_internal->state != STATE_IDLE) return wxTHREAD_RUNNING; p_internal->state = STATE_RUNNING; if (sproc(p_internal->SprocStart, PR_SALL, this) < 0) { p_internal->state = STATE_IDLE; return wxTHREAD_NO_RESOURCE; } return wxTHREAD_NO_ERROR; }
bool_t cldmgr_create( int ( * entry )( void *arg1 ), u_intgen_t inh, ix_t streamix, char *descstr, void *arg1 ) { cld_t *cldp; pid_t cldpid; ASSERT( getpid( ) == cldmgr_parentpid ); cldp = cldmgr_getcld( ); if ( ! cldp ) { mlog( MLOG_NORMAL | MLOG_ERROR | MLOG_PROC, _( "cannot create %s thread for stream %u: " "too many child threads (max allowed is %d)\n"), descstr, streamix, CLD_MAX ); return BOOL_FALSE; } cldp->c_streamix = streamix; cldp->c_entry = entry; cldp->c_arg1 = arg1; cldpid = ( pid_t )sproc( cldmgr_entry, inh, ( void * )cldp ); if ( cldpid < 0 ) { mlog( MLOG_NORMAL | MLOG_ERROR | MLOG_PROC, _( "sproc failed creating %s thread for stream %u: %s\n"), descstr, streamix, strerror( errno )); } else { mlog( MLOG_NITTY | MLOG_PROC, "%s thread created for stream %u: pid %d\n", descstr, streamix, cldpid ); } return cldpid < 0 ? BOOL_FALSE : BOOL_TRUE; }
int nproc(char **argv) { char buf[128]; int pid, i, fd; pid = fork(); switch(pid) { case -1: error("new: fork %r"); case 0: rfork(RFNAMEG|RFNOTEG); sprint(buf, "/proc/%d/ctl", getpid()); fd = open(buf, ORDWR); if(fd < 0) fatal("new: open %s: %r", buf); write(fd, "hang", 4); close(fd); close(0); close(1); close(2); for(i = 3; i < NFD; i++) close(i); open("/dev/cons", OREAD); open("/dev/cons", OWRITE); open("/dev/cons", OWRITE); exec(argv[0], argv); fatal("new: exec %s: %r"); default: install(pid); msg(pid, "waitstop"); notes(pid); sproc(pid); dostop(pid); break; } return pid; }
static int attachfiles(char *aout, int pid) { interactive = 0; if(setjmp(err)) return -1; if(aout) { /* executable given */ if(wtflag) text = open(aout, ORDWR); else text = open(aout, OREAD); if(text < 0) error("%s: can't open %s: %r\n", argv0, aout); readtext(aout); } if(pid) /* pid given */ sproc(pid); return 0; }
void do_threads(SSL_CTX *s_ctx, SSL_CTX *c_ctx) { SSL_CTX *ssl_ctx[2]; int thread_ctx[MAX_THREAD_NUMBER]; int i; ssl_ctx[0] = s_ctx; ssl_ctx[1] = c_ctx; for (i = 0; i < thread_number; i++) { thread_ctx[i] = sproc((void (*)())ndoit, PR_SADDR | PR_SFDS, (void *)ssl_ctx); } printf("reaping\n"); for (i = 0; i < thread_number; i++) { wait(NULL); } printf("irix threads done (%d,%d)\n", s_ctx->references, c_ctx->references); }
void ThreadSGI::spawn() { mThreadPID = sproc(vprThreadFunctorFunction, PR_SADDR | PR_SFDS, &mStartFunctor); if ( mThreadPID == -1 ) { std::ostringstream msg_stream; msg_stream << "Cannot create thread: " << strerror(errno); if ( ENOMEM == errno || EAGAIN == errno ) { throw vpr::ResourceException(msg_stream.str(), VPR_LOCATION); } else if ( EINVAL == errno ) { throw vpr::IllegalArgumentException(msg_stream.str(), VPR_LOCATION); } else { throw vpr::Exception(msg_stream.str(), VPR_LOCATION); } } }
int main(int argc, char **argv) { #ifdef _PR_PTHREADS int rv; pthread_t threadID; pthread_attr_t attr; #elif defined(SOLARIS) int rv; thread_t threadID; #elif defined(WIN32) DWORD rv; unsigned threadID; HANDLE hThread; #elif defined(IRIX) int rv; int threadID; #elif defined(OS2) int rv; TID threadID; #elif defined(XP_BEOS) thread_id threadID; int32 threadRV; status_t waitRV; #endif /* The command line argument: -d is used to determine if the test is being run in debug mode. The regress tool requires only one line output:PASS or FAIL. All of the printfs associated with this test has been handled with a if (debug_mode) test. Usage: test_name [-d] [-c n] */ PLOptStatus os; PLOptState *opt = PL_CreateOptState(argc, argv, "dc:"); while (PL_OPT_EOL != (os = PL_GetNextOpt(opt))) { if (PL_OPT_BAD == os) continue; switch (opt->option) { case 'd': /* debug mode */ debug_mode = 1; break; case 'c': /* loop count */ count = atoi(opt->value); break; default: break; } } PL_DestroyOptState(opt); #if defined(WIN16) printf("attach: This test is not valid for Win16\n"); goto exit_now; #endif if(0 == count) count = DEFAULT_COUNT; /* * To force the implicit initialization of nspr20 */ PR_SetError(0, 0); PR_STDIO_INIT(); /* * Platform-specific code to create a native thread. The native * thread will repeatedly call PR_AttachThread and PR_DetachThread. * The primordial thread waits for this new thread to finish. */ #ifdef _PR_PTHREADS rv = _PT_PTHREAD_ATTR_INIT(&attr); if (debug_mode) PR_ASSERT(0 == rv); else if (0 != rv) { failed_already=1; goto exit_now; } #ifndef _PR_DCETHREADS rv = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); if (debug_mode) PR_ASSERT(0 == rv); else if (0 != rv) { failed_already=1; goto exit_now; } #endif /* !_PR_DCETHREADS */ rv = _PT_PTHREAD_CREATE(&threadID, attr, threadStartFunc, NULL); if (rv != 0) { fprintf(stderr, "thread creation failed: error code %d\n", rv); failed_already=1; goto exit_now; } else { if (debug_mode) printf ("thread creation succeeded \n"); } rv = _PT_PTHREAD_ATTR_DESTROY(&attr); if (debug_mode) PR_ASSERT(0 == rv); else if (0 != rv) { failed_already=1; goto exit_now; } rv = pthread_join(threadID, NULL); if (debug_mode) PR_ASSERT(0 == rv); else if (0 != rv) { failed_already=1; goto exit_now; } #elif defined(SOLARIS) rv = thr_create(NULL, 0, threadStartFunc, NULL, 0, &threadID); if (rv != 0) { if(!debug_mode) { failed_already=1; goto exit_now; } else fprintf(stderr, "thread creation failed: error code %d\n", rv); } rv = thr_join(threadID, NULL, NULL); if (debug_mode) PR_ASSERT(0 == rv); else if (0 != rv) { failed_already=1; goto exit_now; } #elif defined(WIN32) hThread = (HANDLE) _beginthreadex(NULL, 0, threadStartFunc, NULL, STACK_SIZE_PARAM_IS_A_RESERVATION, &threadID); if (hThread == 0) { fprintf(stderr, "thread creation failed: error code %d\n", GetLastError()); failed_already=1; goto exit_now; } rv = WaitForSingleObject(hThread, INFINITE); if (debug_mode)PR_ASSERT(rv != WAIT_FAILED); else if (rv == WAIT_FAILED) { failed_already=1; goto exit_now; } #elif defined(IRIX) threadID = sproc(threadStartFunc, PR_SALL, NULL); if (threadID == -1) { fprintf(stderr, "thread creation failed: error code %d\n", errno); failed_already=1; goto exit_now; } else { if (debug_mode) printf ("thread creation succeeded \n"); sleep(3); goto exit_now; } rv = waitpid(threadID, NULL, 0); if (debug_mode) PR_ASSERT(rv != -1); else if (rv != -1) { failed_already=1; goto exit_now; } #elif defined(OS2) threadID = (TID) _beginthread((void *)threadStartFunc, NULL, 32768, NULL); if (threadID == -1) { fprintf(stderr, "thread creation failed: error code %d\n", errno); failed_already=1; goto exit_now; } rv = DosWaitThread(&threadID, DCWW_WAIT); if (debug_mode) { PR_ASSERT(rv == NO_ERROR); } else if (rv != NO_ERROR) { failed_already=1; goto exit_now; } #elif defined(XP_BEOS) threadID = spawn_thread(threadStartFunc, NULL, B_NORMAL_PRIORITY, NULL); if (threadID <= B_ERROR) { fprintf(stderr, "thread creation failed: error code %08lx\n", threadID); failed_already = 1; goto exit_now; } if (resume_thread(threadID) != B_OK) { fprintf(stderr, "failed starting thread: error code %08lx\n", threadID); failed_already = 1; goto exit_now; } waitRV = wait_for_thread(threadID, &threadRV); if (debug_mode) PR_ASSERT(waitRV == B_OK); else if (waitRV != B_OK) { failed_already = 1; goto exit_now; } #else if (!debug_mode) failed_already=1; else printf("The attach test does not apply to this platform because\n" "either this platform does not have native threads or the\n" "test needs to be written for this platform.\n"); goto exit_now; #endif exit_now: if(failed_already) return 1; else return 0; }
int main(int argc, char *argv[]) { int c; int i; GLfloat mat_specular[] = { 0.7, 0.7, 0.7, 1.0 }; GLfloat mat_shininess[] = { 40.0 }; GLfloat light_position[] = { 4.5, 0.0, 4.5, 0.0 }; glutInit(&argc, argv); num_disks = MAX_DISKS; while((c = getopt(argc, argv, "n:s:m:")) != -1) { switch (c) { case 'n': num_disks = atoi(optarg); if (num_disks < 1 || num_disks > MAX_DISKS) { num_disks = MAX_DISKS; } break; case 's': spinning = atoi(optarg) ? 1 : 0; break; case 'm': motion = atoi(optarg) ? 1 : 0; break; default: break; } } glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); glutCreateWindow("Hanoi"); glutDisplayFunc(display); glutVisibilityFunc(visible); glMatrixMode(GL_PROJECTION); gluPerspective(40.0, 1.0, 0.1, 10.0); glMatrixMode(GL_MODELVIEW); gluLookAt(0, 5.5, 3.5, 0, 0, 0, 0, 0, 1); glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); #ifndef TOOSLOW glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); glEnable(GL_COLOR_MATERIAL); #endif #ifndef TOOSLOW glShadeModel(GL_SMOOTH); #endif glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); #ifndef TOOSLOW glLightfv(GL_LIGHT0, GL_POSITION, light_position); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); #endif glDepthFunc(GL_LEQUAL); glClearColor(0.3, 0.3, 0.3, 0.0); #ifndef TOOSLOW glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); #endif glPolygonMode(GL_FRONT, GL_FILL); glutCreateMenu(menu); glutAddMenuEntry("Toggle motion", 2); glutAddMenuEntry("Toggle spinning", 3); glutAddMenuEntry("Quit", 666); glutAttachMenu(GLUT_RIGHT_BUTTON); #if defined(GL_POLYGON_OFFSET_EXT) if (glutExtensionSupported("GL_EXT_polygon_offset")) { glPolygonOffsetEXT(0.5, 0.0); glEnable(GL_POLYGON_OFFSET_EXT); } #endif poledlist(DL_POLE); floordlist(DL_FLOOR); disks_on_poles[0].num_disks = num_disks; for (i=0; i<num_disks; i++) { diskdlist(DL_DISK+i, 0.3 + i*0.1); disks_on_poles[0].disks[num_disks-i-1] = i; disk_offset[i][Z] = 0.2*(num_disks-i-1); } /* * start hanoi instruction engine */ { int engine_args[2]; extern void engine(int *); int p[2]; prctl(PR_SETEXITSIG, SIGTERM); if (-1 == pipe(p)) { perror("can't pipe"); exit(1); } engine_args[0] = num_disks; engine_args[1] = p[1]; engine_fd = p[0]; engine_pid = sproc((void(*)(void *))engine, PR_SALL, (void *)engine_args); if (engine_pid == -1) { perror("can't sproc"); exit(1); } } glutMainLoop(); /*NOTREACHED*/ return 0; /* ANSI C requires main to return int. */ }