/*ARGSUSED*/ static void power_button_monitor(void *arg) { struct pollfd pfd; int events, ret; if (ioctl(pb_fd, PB_BEGIN_MONITOR, NULL) == -1) { logerror("Failed to monitor the power button."); thr_exit((void *) 0); } pfd.fd = pb_fd; pfd.events = POLLIN; /*CONSTCOND*/ while (1) { if (poll(&pfd, 1, INFTIM) == -1) { logerror("Failed to poll for power button events."); thr_exit((void *) 0); } if (!(pfd.revents & POLLIN)) continue; /* * Monitor the power button, but only take action if * gnome-power-manager is not running. * * ret greater than 0 means could not find process. */ ret = system("/usr/bin/pgrep -fx gnome-power-manager"); if (ioctl(pfd.fd, PB_GET_EVENTS, &events) == -1) { logerror("Failed to get power button events."); thr_exit((void *) 0); } if ((ret > 0) && (events & PB_BUTTON_PRESS) && (poweroff(NULL, power_button_cmd) != 0)) { logerror("Power button is pressed, powering " "down the system!"); /* * Send SIGPWR signal to the init process to * shut down the system. */ if (kill(1, SIGPWR) == -1) (void) uadmin(A_SHUTDOWN, AD_POWEROFF, 0); } /* * Clear any power button event that has happened * meanwhile we were busy processing the last one. */ if (ioctl(pfd.fd, PB_GET_EVENTS, &events) == -1) { logerror("Failed to get power button events."); thr_exit((void *) 0); } } }
static void autos3_monitor(void) { struct pollfd poll_fd; srn_event_info_t srn_event; /* contains suspend type */ int fd, ret; fd = open(SRN, O_RDWR|O_EXCL|O_NDELAY); if (fd == -1) { logerror("Unable to open %s: %s", SRN, strerror(errno)); thr_exit((void *) errno); } /* * Tell device we want the special sauce */ ret = ioctl(fd, SRN_IOC_AUTOSX, NULL); if (ret == -1) { logerror("Ioctl SRN_IOC_AUTOSX failed: %s", strerror(errno)); (void) close(fd); thr_exit((void *) errno); } poll_fd.fd = fd; /*CONSTCOND*/ while (1) { poll_fd.revents = 0; poll_fd.events = POLLIN; if (poll(&poll_fd, 1, -1) < 0) { switch (errno) { case EINTR: case EAGAIN: continue; default: logerror("Poll error: %s", strerror(errno)); (void) close(fd); thr_exit((void *) errno); } } ret = ioctl(fd, SRN_IOC_NEXTEVENT, &srn_event); if (ret == -1) { logerror("ioctl error: %s", strerror(errno)); (void) close(fd); thr_exit((void *) errno); } switch (srn_event.ae_type) { case 3: /* S3 */ if (powerd_debug) logerror("ioctl returns type: %d", srn_event.ae_type); break; default: logerror("Unsupported target state %d", srn_event.ae_type); continue; } (void) poweroff("AutoS3", autoS3_cmd); continue; } }
/*ARGSUSED*/ static void power_button_monitor(void *arg) { struct pollfd pfd; int events; if (ioctl(pb_fd, PB_BEGIN_MONITOR, NULL) == -1) { logerror("Failed to monitor the power button."); thr_exit((void *) 0); } pfd.fd = pb_fd; pfd.events = POLLIN; /*CONSTCOND*/ while (1) { if (poll(&pfd, 1, INFTIM) == -1) { logerror("Failed to poll for power button events."); thr_exit((void *) 0); } if (!(pfd.revents & POLLIN)) continue; if (ioctl(pfd.fd, PB_GET_EVENTS, &events) == -1) { logerror("Failed to get power button events."); thr_exit((void *) 0); } if ((events & PB_BUTTON_PRESS) && (poweroff(NULL, power_button_cmd) != 0)) { logerror("Power button is pressed, powering " "down the system!"); /* * Send SIGPWR signal to the init process to * shut down the system. */ if (kill(1, SIGPWR) == -1) (void) uadmin(A_SHUTDOWN, AD_POWEROFF, 0); } /* * Clear any power button event that has happened * meanwhile we were busy processing the last one. */ if (ioctl(pfd.fd, PB_GET_EVENTS, &events) == -1) { logerror("Failed to get power button events."); thr_exit((void *) 0); } } }
/* * tell robot to move media between two slots. Runs as a thread. * * Programming note: The parameter passed in was malloc'ed, be sure * to free it before thr_exit. */ void * move_slots( void *vcmd) { sam_cmd_fifo_t *command = (sam_cmd_fifo_t *)vcmd; dev_ent_t *device; /* all commands are sent to the robot, get robots device entry */ device = DEV_ENT(DEV_ENT(command->eq)->fseq); if (IS_ROBOT(device) && (device->status.b.ready && device->status.b.present)) { message_request_t *message; message = (message_request_t *)SHM_REF_ADDR(device->dt.rb.message); (void) mutex_lock(&message->mutex); while (message->mtype != MESS_MT_VOID) { cond_wait(&message->cond_i, &message->mutex); } memset(&message->message, 0, sizeof (sam_message_t)); message->message.magic = MESSAGE_MAGIC; message->message.command = MESS_CMD_MOVE; message->message.exit_id = command->exit_id; message->message.param.cmdmove_request.flags = command->flags; message->message.param.cmdmove_request.slot = command->slot; message->message.param.cmdmove_request.d_slot = command->d_slot; message->mtype = MESS_MT_NORMAL; cond_signal(&message->cond_r); mutex_unlock(&message->mutex); } free(command); /* free the command buffer */ thr_exit(NULL); /* LINTED Function has no return statement */ }
void * sub_d(void *arg) { thread_t thr_b = (thread_t) arg; int i; thread_t thr_e, ret_thr; void *status; printf("D: In thread D...\n"); if (thr_create(NULL, 0, sub_e, NULL, THR_NEW_LWP, &thr_e)) fprintf(stderr,"Can't create thr_e\n"), exit(1); printf("D: Created thread E:%d\n", thr_e); printf("D: Continue B thread = %d\n", thr_b); thr_continue(thr_b); printf("D: Join E thread\n"); if(thr_join(thr_e,(thread_t *)&ret_thr, &status)) fprintf(stderr,"thr_join Error\n"), exit(1); printf("D: E thread (%d) returned thread (%d) w/status %d\n", thr_e, ret_thr, (int) status); /* process */ for (i=0;i<1000000*(int)thr_self();i++); printf("D: Thread exiting...\n"); thr_exit((void *)55); }
/* * tell robot to mount media by slot. Runs as a thread. * * Programming note: The parameter passed in was malloc'ed, be sure * to free it before thr_exit. */ void * mount_slot( void *vcmd) { sam_cmd_fifo_t *command = (sam_cmd_fifo_t *)vcmd; message_request_t *message; /* valid equipment was verified in the caller */ message = (message_request_t *)SHM_REF_ADDR( (DEV_ENT(command->eq))->dt.rb.message); (void) mutex_lock(&message->mutex); while (message->mtype != MESS_MT_VOID) { cond_wait(&message->cond_i, &message->mutex); } (void) memset(&message->message, 0, sizeof (sam_message_t)); message->message.magic = MESSAGE_MAGIC; message->message.command = MESS_CMD_MOUNT; message->message.exit_id = command->exit_id; message->message.param.mount_request.flags = command->flags; message->message.param.mount_request.slot = command->slot; message->message.param.mount_request.part = command->part; message->mtype = MESS_MT_NORMAL; cond_signal(&message->cond_r); mutex_unlock(&message->mutex); free(command); /* free the command buffer */ thr_exit(NULL); /* LINTED Function has no return statement */ }
/* * tell robot to clean a drive. Runs as a thread. * * Programming note: The parameter passed in was malloc'ed, be sure * to free it before thr_exit. */ void * clean_drive( void *vcmd) { sam_cmd_fifo_t *command = (sam_cmd_fifo_t *)vcmd; dev_ent_t *device; device = DEV_ENT(DEV_ENT(command->eq)->fseq); if (IS_ROBOT(device) && device->state < DEV_IDLE) { message_request_t *message; message = (message_request_t *)SHM_REF_ADDR(device->dt.rb.message); (void) mutex_lock(&message->mutex); while (message->mtype != MESS_MT_VOID) { cond_wait(&message->cond_i, &message->mutex); } memset(&message->message, 0, sizeof (sam_message_t)); message->message.magic = MESSAGE_MAGIC; message->message.command = MESS_CMD_CLEAN; message->message.param.clean_request.eq = command->eq; message->mtype = MESS_MT_NORMAL; cond_signal(&message->cond_r); mutex_unlock(&message->mutex); } free(command); /* free the command buffer */ thr_exit(NULL); /* LINTED Function has no return statement */ }
void *child(void *arg){ printf("child\n"); thr_exit(); printf("child finished\n"); return NULL; }
void my_timer_fire(Timer *timer) { printf("%s I have fired %d\n", timer->name, time (NULL)); #ifdef SOLARIS thr_exit (0); #endif /* SOLARIS */ }
void * sub_e(void *arg) { int i; thread_t ret_thr; void *status; printf("E: In thread E...\n"); printf("E: Join A thread\n"); if(thr_join(thr_a,(thread_t *)&ret_thr, &status)) fprintf(stderr,"thr_join Error\n"), exit(1); printf("E: A thread (%d) returned thread (%d) w/status %d\n", ret_thr, ret_thr, (int) status); printf("E: Join B thread\n"); if(thr_join(thr_b,(thread_t *)&ret_thr, &status)) fprintf(stderr,"thr_join Error\n"), exit(1); printf("E: B thread (%d) returned thread (%d) w/status %d\n", thr_b, ret_thr, (int) status); printf("E: Join C thread\n"); if(thr_join(thr_c,(thread_t *)&ret_thr, &status)) fprintf(stderr,"thr_join Error\n"), exit(1); printf("E: C thread (%d) returned thread (%d) w/status %d\n", thr_c, ret_thr, (int) status); for (i=0;i<1000000*(int)thr_self();i++); printf("E: Thread exiting...\n"); thr_exit((void *)44); }
void * sub_c(void *arg) { void *status; int i; thread_t main_thr, ret_thr; main_thr = (thread_t)arg; printf("C: In thread C...\n"); if (thr_create(NULL, 0, sub_f, (void *)0, THR_BOUND|THR_DAEMON, NULL)) fprintf(stderr, "Can't create thr_f\n"), exit(1); printf("C: Join main thread\n"); if (thr_join(main_thr,(thread_t *)&ret_thr, &status)) fprintf(stderr, "thr_join Error\n"), exit(1); printf("C: Main thread (%d) returned thread (%d) w/status %d\n", main_thr, ret_thr, (int) status); /* process */ for (i=0;i<1000000*(int)thr_self();i++); printf("C: Thread exiting...\n"); thr_exit((void *)88); }
/****************************************************************** * KpThreadExit (Solaris Version) * * Description * * This function causes the currently executing thread to exit. * * Author * mjb * * Created * July 5, 1994 *****************************************************************************/ void KpThreadExit (KpInt32_t exitCode) { thr_exit (&exitCode); } /* KpThreadExit */
/* * When SIGUSR1 is received, exit the thread */ void catch_sigusr1(void) { rcm_log_message(RCM_DEBUG, "SIGUSR1 received in thread %d\n", thr_self()); cleanup_poll_thread(); thr_exit(NULL); }
/* Terminate the current thread. */ int __objc_thread_exit(void) { /* exit the thread */ thr_exit(&__objc_thread_exit_status); /* Failed if we reached here */ return -1; }
static void ret (int status) { #ifdef HAVE_PTHREAD_H pthread_exit(&status); #else thr_exit (&status); #endif }
void excpetion_handler(void *arg, ureg_t *ureg) { void *faultaddr = NULL; void *phdlrstack = NULL; int ret = ERROR; thread_t *pthread = NULL; int tid = gettid(); /* if something rather than page fault */ if ((NULL == ureg) || (SWEXN_CAUSE_PAGEFAULT != ureg->cause) || (0 != ((ureg->error_code) & 1))) thr_exit((void *)-1); /* get the fault address */ faultaddr = (void *)ureg->cr2; if (g_root_tid == tid) { phdlrstack = (void *)ROOT_HDLR_STACK + 1; /* root thread extends stack */ ret = root_stack_extend(faultaddr); } else { /* get the thread from hash table */ pthread = get_thread_by_tid(tid); if (NULL == pthread) thr_exit((void *)-1); phdlrstack = pthread->stack_base + 1; /* other threads extend stack */ ret = thread_stack_extend(faultaddr, pthread); } /* no more space to extend, terminate this thread */ if (OK != ret) { lprintf("+++++++++++++ tid%d ret err++++++++++++\n", tid); thr_exit((void *)-1); } /* re install handler */ register_exception_handler(phdlrstack, ureg); return; }
void ExitHandler(int sig) { thread_t id; id = thr_self(); fprintf(stderr, "ExitHandler thread id: %d\n", id); thr_exit(0); }
/* * set new state for a device. * * Programming note: The parameter passed in was malloc'ed, be sure * to free it before thr_exit. */ void * set_state( void *vcmd) { int old_state; sam_cmd_fifo_t *command = (sam_cmd_fifo_t *)vcmd; dev_ent_t *device, *robot = NULL; message_request_t *message = NULL; /* equipment was verified in the caller */ device = DEV_ENT(command->eq); if (device->fseq) { robot = DEV_ENT(device->fseq); } if (command->state >= DEV_ON && command->state <= DEV_DOWN && command->state != DEV_NOALLOC) { old_state = device->state; if (robot != NULL) { device = robot; if (IS_ROBOT(device) && device->status.b.present) { message = (message_request_t *)SHM_REF_ADDR( device->dt.rb.message); } } else if (IS_OPTICAL(device) || IS_TAPE(device)) { /* send to scanner */ message = (message_request_t *)SHM_REF_ADDR( ((shm_ptr_tbl_t *)master_shm.shared_memory)-> scan_mess); } if (message != NULL) { (void) mutex_lock(&message->mutex); while (message->mtype != MESS_MT_VOID) { cond_wait(&message->cond_i, &message->mutex); } memset(&message->message, 0, sizeof (sam_message_t)); message->message.magic = MESSAGE_MAGIC; message->message.command = MESS_CMD_STATE; message->message.exit_id = command->exit_id; message->message.param.state_change.flags = command->flags; message->message.param.state_change.eq = command->eq; message->message.param.state_change.old_state = old_state; message->message.param.state_change.state = command->state; message->mtype = MESS_MT_NORMAL; cond_signal(&message->cond_r); mutex_unlock(&message->mutex); } } free(command); /* free the command buffer */ thr_exit(NULL); /* LINTED Function has no return statement */ }
int tmpi_Abort(MPI_Comm comm, int code) { if (comm==MPI_COMM_WORLD) { MPI_Finalize(); // tmpi_user_end(); thr_exit(code); } /* should never reach here */ return code; }
void install_autostack(void *stack_high, void *stack_low) { /* check page alignment */ if (0 != ((unsigned int)stack_low & PAGE_ALIGN_TEST)) thr_exit((void *)-1); g_stackinfo.rootstack_low = stack_low; g_stackinfo.rootstack_hi = stack_high; g_stackinfo.max_stacksize = (int)stack_high - ROOT_HDLR_STACK; g_root_tid = gettid(); /* space for the stack of root thread */ if (0 > new_pages((void *)(ROOT_HDLR_STACK - PAGE_SIZE + 1), PAGE_SIZE)) thr_exit((void *)-1); /* register a exception handler */ register_exception_handler((void *)ROOT_HDLR_STACK + 1, NULL); return; }
/* * add catalog command * * Programming note: The parameter passed in was malloc'ed, be sure * to free it before thr_exit. */ void * add_catalog_cmd( void *vcmd) { sam_cmd_fifo_t *command = (sam_cmd_fifo_t *)vcmd; dev_ent_t *device; message_request_t *message; if (command->vsn[0] == '\0' && !(command->flags & ADDCAT_BARCODE)) { sam_syslog(LOG_INFO, catgets(catfd, SET, 11008, "Add catalog, vsn not supplied.")); } else { device = DEV_ENT(DEV_ENT(command->eq)->fseq); if ((IS_GENERIC_API(device->type) || device->type == DT_STKAPI || device->type == DT_SONYPSC || device->type == DT_IBMATL) || device->type == DT_HISTORIAN && (device->state < DEV_IDLE) && (device->status.b.ready && device->status.b.present)) { message = (message_request_t *) SHM_REF_ADDR(device->dt.rb.message); (void) mutex_lock(&message->mutex); while (message->mtype != MESS_MT_VOID) { cond_wait(&message->cond_i, &message->mutex); } memset(&message->message, 0, sizeof (sam_message_t)); message->message.magic = MESSAGE_MAGIC; message->message.command = MESS_CMD_ADD; message->message.exit_id = command->exit_id; message->mtype = MESS_MT_NORMAL; message->message.param.addcat_request.media = command->media; message->message.param.addcat_request.flags = command->flags; memmove(&message->message.param.addcat_request.vsn[0], &command->vsn[0], sizeof (vsn_t)); if (command->flags & ADDCAT_BARCODE) { memccpy(&message-> message.param.addcat_request.bar_code[0], &command->info[0], '\0', BARCODE_LEN); } cond_signal(&message->cond_r); mutex_unlock(&message->mutex); } } free(command); /* free the command buffer */ thr_exit(NULL); /* LINTED Function has no return statement */ }
void * sub_b(void *arg) { int i; printf("B: In thread B...\n"); /* process */ for (i=0;i<1000000*(int)thr_self();i++); printf("B: Thread exiting...\n"); thr_exit((void *)66); }
int main() { thr_init(16 * PAGE_SIZE); (void) thr_create(waiter, (void *) thr_getid()); //sleep(10); /* optional, of course!! */ thr_exit((void *)'!'); while(1) continue; /* placate compiler portably */ }
void * waiter(void *p) { int status; thr_join((int)p, (void **)&status); //printf("Thread %d exited '%c'\n", (int)p, (char)status); thr_exit((void *) 0); while(1) continue; /* placate compiler portably */ }
/* * unload_cmd. Thread version of unload command. * This is used in the main loop cannot get the mutex. Instead of waiting * around, it called this routine. */ void * unload_cmd( void *vdev) { dev_ent_t *device = (dev_ent_t *)vdev; if (mutex_lock(&device->mutex) != 0) { if (device->status.b.ready) { device->status.b.unload = TRUE; } mutex_unlock(&device->mutex); } thr_exit(NULL); /* LINTED Function has no return statement */ }
void *sub_a(void *arg) { thread_t thr_b = (thread_t) arg; thread_t thr_d; int i; printf("A: In thread A...\n"); if (thr_create(NULL, 0, sub_d, (void *)thr_b, THR_NEW_LWP, &thr_d)) fprintf(stderr, "Can't create thr_d\n"), exit(1); printf("A: Created thread D:%d\n", thr_d); /* process */ for (i=0;i<1000000*(int)thr_self();i++); printf("A: Thread exiting...\n"); thr_exit((void *)77); }
int main(int argc, char ** argv) { int error; int i; int retcode; thrgrp_group_t tg; try(thr_init(7*1024)); try(mutex_init(&worldLock)); try(mutex_init(&updateLock)); try(cond_init(&updates)); try(cond_init(&gameOver)); initScreen(); thrgrp_init_group(&tg); try(thrgrp_create(&tg,update, 0)); try(thrgrp_create(&tg,controlThread, 0)); try(thrgrp_create(&tg,targetThread, 0)); try(thrgrp_create(&tg,scoreThread, 0)); /** finish drawing the screen **/ //scheduleUpdate(); /** lock down until the game finishes **/ mutex_lock(&worldLock); cond_wait(&gameOver, &worldLock); mutex_unlock(&worldLock); /** game is over **/ cond_signal(&updates); /** Once the game is over, cleanup after yourself! **/ for(i=0; i<NUM_THREADS; i++) { try(thrgrp_join(&tg, (void **)&retcode)); printf("Worker thread returned with code %d.\n",retcode); } thr_exit(0); return 0; }
/**************************************************************************** * Producer Thread: Produce a widget ****************************************************************************/ void *Producer(void *arg) { SPC prod; int myNumber; prod.id = *((int*)arg); prod.num = 0; prod.type = PRODUCER; srand48((long)time(0)); for(;;) { /* Lock producers and check if there are more widgets to produce */ mutex_lock(&mutex_prod); if(prod_count >= NUMBER_PRODUCTS) { mutex_unlock(&mutex_prod); thr_exit(&prod); } myNumber = prod_count; ++prod_count; mutex_unlock(&mutex_prod); sleep(lrand48() % 5 + 1); /* Lock the buffer and produce a widget */ mutex_lock(&mutex_buffer); if(buffer_used >= BUFFER_SIZE) { printf("PRODUCER-%d: Buffer full, waiting.\n", prod.id); cond_wait(&cond_not_full, &mutex_buffer); } printf("PRODUCER-%d: I will produce widget %d.\n", prod.id, myNumber); buffer[buffer_insert] = myNumber; buffer_insert = (buffer_insert + 1) % BUFFER_SIZE; ++buffer_used; cond_signal(&cond_not_empty); mutex_unlock(&mutex_buffer); ++prod.num; } }
void main() { thread_t main_thr; main_thr = thr_self(); printf("Main thread = %d\n", main_thr); if (thr_create(NULL, 0, sub_b, NULL, THR_SUSPENDED|THR_NEW_LWP, &thr_b)) fprintf(stderr,"Can't create thr_b\n"), exit(1); if (thr_create(NULL, 0, sub_a, (void *)thr_b, THR_NEW_LWP, &thr_a)) fprintf(stderr,"Can't create thr_a\n"), exit(1); if (thr_create(NULL, 0, sub_c, (void *)main_thr, THR_NEW_LWP, &thr_c)) fprintf(stderr,"Can't create thr_c\n"), exit(1); printf("Main Created threads A:%d B:%d C:%d\n", thr_a, thr_b, thr_c); printf("Main Thread exiting...\n"); thr_exit((void *)main_thr); }
/*! Ends execution of the calling thread and wakes up any threads waiting for its termination. */ void QThread::exit() { dictMutex->lock(); QThread *there = thrDict->find(QThread::currentThread()); if (there) { there->d->running = FALSE; there->d->finished = TRUE; there->d->thread_done.wakeAll(); } dictMutex->unlock(); #if defined(_OS_SOLARIS_) thr_exit(0); #else pthread_exit(0); #endif }