/* * Get the current NFS domain. * * If NFSMAPID_DOMAIN is set in /etc/default/nfs, then it is the NFS domain; * otherwise, the DNS domain is used. */ void check_domain(int sighup) { const char *whoami = "check_domain"; static int setup_done = 0; static cb_t cb; /* * Construct the arguments to be passed to libmapid interface * If called in response to a SIGHUP, reset any cached DNS TXT * RR state. */ cb.fcn = cb_update_domain; cb.signal = sighup; mapid_reeval_domain(&cb); /* * Restart the signal handler thread if we're still setting up */ if (!setup_done) { setup_done = 1; if (thr_continue(sig_thread)) { syslog(LOG_ERR, gettext("%s: Fatal error: signal " "handler thread could not be restarted."), whoami); exit(6); } } }
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); }
Thread ThreadCreate( #if defined(POSIX_THREADS) ThreadEntryPoint entry, void * client_data) { thread_t id; thr_create(NULL, 0, entry, client_data, THR_BOUND | THR_NEW_LWP, &id); thr_continue(id); return(id); }
void main (int argc, char **argv) { #ifdef _REENTRANT int i; #ifdef HAVE_PTHREAD_H pthread_t tids[MAX_THREADS]; #endif #endif pid_t pid; ARGC = argc; ARGV = argv; /* PRIME */ scan_passwd(); pid = fork(); if (pid == 0) { printf("IN CHILD\n"); } else { printf("IN PARENT\n"); } #ifdef _REENTRANT for (i = 0; i < MAX_THREADS; i++) { #ifdef HAVE_PTHREAD_H pthread_create(&tids[i], NULL, test_passwd, NULL); #else thread_t tid; thr_create (NULL, 0, test_passwd, NULL, 0, &tid); thr_continue (tid); #endif /* HAVE_PTHREAD_H */ } #ifdef HAVE_PTHREAD_H for (i = 0; i < MAX_THREADS; i++) pthread_join(tids[i], NULL); #else while (thr_join (NULL, NULL, NULL) == 0); #endif #else test_passwd (); #endif exit (0); }
main() { char str[80]; thread_t ctid; /* create the thread counter subroutine */ thr_create(NULL, 0, counter, 0, THR_NEW_LWP|THR_DETACHED, &ctid); while(1) { gets(str); thr_suspend(ctid); mutex_lock(&count_lock); printf("\n\nCOUNT = %d\n\n", count); mutex_unlock(&count_lock); thr_continue(ctid); } return(0); }
int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void * (*start_routine)(void *), void *arg) { ulwp_t *self = curthread; const thrattr_t *ap = attr? attr->__pthread_attrp : def_thrattr(); const pcclass_t *pccp; long flag; pthread_t tid; int error; update_sched(self); if (ap == NULL) return (EINVAL); /* validate explicit scheduling attributes */ if (ap->inherit == PTHREAD_EXPLICIT_SCHED && (ap->policy == SCHED_SYS || (pccp = get_info_by_policy(ap->policy)) == NULL || ap->prio < pccp->pcc_primin || ap->prio > pccp->pcc_primax)) return (EINVAL); flag = ap->scope | ap->detachstate | ap->daemonstate | THR_SUSPENDED; error = _thrp_create(ap->stkaddr, ap->stksize, start_routine, arg, flag, &tid, ap->guardsize, ap->name); if (error == 0) { /* * Record the original inheritence value for * pthread_getattr_np(). We should always be able to find the * thread. */ (void) _thr_setinherit(tid, ap->inherit); if (ap->inherit == PTHREAD_EXPLICIT_SCHED && (ap->policy != self->ul_policy || ap->prio != (self->ul_epri ? self->ul_epri : self->ul_pri))) { /* * The SUSv3 specification requires pthread_create() * to fail with EPERM if it cannot set the scheduling * policy and parameters on the new thread. */ error = _thr_setparam(tid, ap->policy, ap->prio); } if (error) { /* * We couldn't determine this error before * actually creating the thread. To recover, * mark the thread detached and cancel it. * It is as though it was never created. */ ulwp_t *ulwp = find_lwp(tid); if (ulwp->ul_detached == 0) { ulwp->ul_detached = 1; ulwp->ul_usropts |= THR_DETACHED; (void) __lwp_detach(tid); } ulwp->ul_cancel_pending = 2; /* cancelled on creation */ ulwp->ul_cancel_disabled = 0; ulwp_unlock(ulwp, self->ul_uberdata); } else if (thread) { *thread = tid; } (void) thr_continue(tid); } /* posix version expects EAGAIN for lack of memory */ if (error == ENOMEM) error = EAGAIN; return (error); }
static inline void ccxx_resume(cctid_t tid) { thr_continue((thread_t)tid); }