/* * ======== CERuntime_init ======== */ Void CERuntime_init(Void) { GT_init(); /* allow user to over-ride via CE_TRACE. */ GT_set(Global_getenv("CE_TRACE")); Global_init(); Sem_init(); SemMP_init(); Memory_init(); Queue_init(); Comm_init(); Thread_init(); Processor_init(); LockMP_init(); /* Must be called before DMAN3_init() */ Algorithm_init(); XdmUtils_init(); Lock_init(); Engine_init(); Server_init(); }
Thread *thread_start(void *func, void *args) { Thread *thread = malloc(sizeof(Thread)); if (thread && Thread_init(thread, func, args) != 0) { free(thread); } return thread; }
Thread::Thread(PKSTART_ROUTINE callBack, int stackSize) { if(stackSize < 131072) stack_size = 65536; //Default stack size is 65536, which should be enough, unless there is need for a > 128k stack. stack_size = stackSize; callback = callBack; Thread_init(); }
int main(int argc, char *argv[]) { struct args args; Thread_init(); args.c = Chan_new(); Thread_new((int (*)(void *))source, &args, sizeof args, NULL); args.n = argc > 2 ? atoi(argv[2]) : 5; args.nprime = argc > 1 ? atoi(argv[1]) : 100; Thread_new((int (*)(void *))sink, &args, sizeof args, NULL); Thread_exit(0); return 0; }
int main(int argc, char* argv[]) { struct args args; Thread_init(1, NULL); args.c = Chan_new(); Thread_new(source, &args, sizeof args, NULL); args.n = argc > 2 ? atoi(argv[2]) : 5; args.last = argc > 1 ? atoi(argv[1]) : 1000; Thread_new(sink, &args, sizeof args, NULL); Thread_exit(EXIT_SUCCESS); return EXIT_SUCCESS; }
main(int argc, char *argv[]) { int i, n = 100000, *x, preempt; preempt = Thread_init(1, NULL); assert(preempt == 1); if (argc >= 2) n = atoi(argv[1]); x = CALLOC(n, sizeof (int)); srand(time(NULL)); for (i = 0; i < n; i++) x[i] = rand(); sort(x, n, argc, argv); for (i = 1; i < n; i++) if (x[i] < x[i-1]) break; assert(i == n); Thread_exit(EXIT_SUCCESS); return EXIT_SUCCESS; }
int main(int argc, char *argv[]){ int m = 5; int preempt; preempt = Thread_init(1, NULL); assert(preempt == 1); if (argc >= 2){ m = atoi(argv[1]); } n = 0; // increment n unsafely { int i; for (i = 0; i < m; i++){ Thread_new(unsafe, &n, 0, NULL); // 创建m个线程 } Thread_join(NULL); } Fmt_print("%d == %d\n", n, NBUMP * m); n = 0; // increment n safely { int i; struct args args; Sem_T mutex; Sem_init(&mutex, 1); args.mutex = &mutex; args.ip = &n; for (i = 0; i < m; i++){ Thread_new(safe, &args, sizeof(args), NULL); } Thread_join(NULL); } Fmt_print("%d == %d\n", n, NBUMP * m); Thread_exit(EXIT_SUCCESS); return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { int i, j; int m = argc > 1 ? atoi(argv[1]) : 4; int n = argc > 2 ? atoi(argv[2]) : 3; Thread_init(); Sem_init(&mutex, 1); for (j = 0; j < n; j++) { struct args args; args.mutex = &mutex; args.ip = &y; for (i = 0; i < m; i++) Thread_new((int (*)(void *))incr, &args, sizeof args, NULL); Thread_join(0); if (y != m*10000) printf("%d:%d\n", j, y); y = 0; } Thread_exit(0); return 0; }
/* * ======== CERuntime_init ======== */ Void CERuntime_init(Void) { extern Void IPC_generatedInit(); GT_init(); /* if CE_DEBUG is set, turn on tracing and DSP auto trace collection */ if (Global_getenv("CE_DEBUG") != NULL) { extern Bool Engine_alwaysCollectDspTrace; extern String Engine_ceDebugDspTraceMask; Engine_alwaysCollectDspTrace = TRUE; if (Global_getenv("CE_DEBUG")[0] == '1') { GT_set("*+67,CE-3,GT_time=0,GT_prefix=1235"); Engine_ceDebugDspTraceMask = "*+67,GT_prefix=1235,GT_time=3"; } else if (Global_getenv("CE_DEBUG")[0] == '2') { GT_set( "*+01234567,CE-3,ti.sdo.ce.osal.SemMP=67,OG=467,OM=4567,OC=67,GT_time=0,GT_prefix=1235"); Engine_ceDebugDspTraceMask = "*+01234567,CR=67,ti.sdo.fc.dman3-2,ti.sdo.fc.dskt2-2,GT_prefix=1235,GT_time=3"; } else { GT_set("*+01234567,CE-3,GT_time=0,GT_prefix=12345"); Engine_ceDebugDspTraceMask = "*+01234567,GT_prefix=12345,GT_time=3"; } } if (Global_getenv("CE_CHECK") != NULL) { extern Bool VISA_checked; /* * Currently just change _this_ processor's value... perhaps we should * enable remote processors as well? */ if (Global_getenv("CE_CHECK")[0] == '1') { VISA_checked = TRUE; /* turn on all GT_7CLASS trace (errors) */ GT_set("*+7"); } else if (Global_getenv("CE_CHECK")[0] == '0') { VISA_checked = FALSE; } else { /* leave it whatever it was... maybe we should drop a warning? */ } } /* allow user to over-ride via CE_TRACE. */ GT_set(Global_getenv("CE_TRACE")); IPC_generatedInit(); Global_init(); Sem_init(); SemMP_init(); Memory_init(); Queue_init(); Comm_init(); Thread_init(); Processor_init(); LockMP_init(); /* Must be called before DMAN3_init() */ Algorithm_init(); XdmUtils_init(); Lock_init(); Engine_init(); Server_init(); }
Thread::Thread(PKSTART_ROUTINE callBack) { stack_size = 65536; callback = callBack; Thread_init(); }