本文整理汇总了C++中sthread_create函数的典型用法代码示例。如果您正苦于以下问题:C++ sthread_create函数的具体用法?C++ sthread_create怎么用?C++ sthread_create使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sthread_create函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_parallel
static void test_parallel(void)
{
sthread_t st[2];
sc_t sc[2];
int p[2];
void *ret;
if (pipe(p) == -1)
err(1, "pipe()");
sc_init(&sc[0]);
sc_fd_add(&sc[0], p[0], PROT_READ | PROT_WRITE);
if (sthread_create(&st[0], &sc[0], parallel_read, (void*) (long) p[0]))
err(1, "sthread_create()");
sc_init(&sc[1]);
sc_fd_add(&sc[1], p[1], PROT_READ | PROT_WRITE);
if (sthread_create(&st[1], &sc[1], parallel_write, (void*) (long) p[1]))
err(1, "sthread_create()");
if (sthread_join(st[0], &ret) == -1)
err(1, "sthread_join()");
if (sthread_join(st[1], NULL) == -1)
err(1, "sthread_join()");
if (ret != (void*) 0x666)
errx(1, "ret is %p", ret);
close(p[0]);
close(p[1]);
}
示例2: main
int main(int argc, char **argv)
{
int counter0 = 0;
int c1, c2;
sthread_init();
if (sthread_create(thread_1, (void*)0, 10) == NULL) {
printf("sthread_create failed\n");
exit(1);
}
if (sthread_create(thread_2, (void*)0, 1) == NULL) {
printf("sthread_create failed\n");
exit(1);
}
printf("created threads\n");
for(; counter0 < 30000000; counter0++);
c1 = counter1;
c2 = counter2;
printf("1: %i, 2: %i\n", c1, c2);
printf("2/1: %f\n", ((float)c2)/c1);
if (c2/c1 >= 6 && c2/c1 <= 14)
printf("PASSED\n");
return 0;
}
示例3: main
int main(int argc, char **argv)
{
printf("Testing sthread_create, impl: %s\n",
(sthread_get_impl() == STHREAD_PTHREAD_IMPL) ? "pthread" : "user");
sthread_init();
if (sthread_create(thread1, (void*)1, 10) == NULL) {
printf("sthread_create failed\n");
exit(-1);
}
if (sthread_create(thread2, (void*)1, 10) == NULL) {
printf("sthread_create failed\n");
exit(-1);
}
printf("in main\n");
sthread_sleep(10000);
printf("\ntwo threads runqueue active in priority 10\n");
sthread_dump();
sthread_sleep(10000);
printf("\ntwo threads runqueue active in priority 10\n");
sthread_dump();
printf("out main\n");
return 0;
}
示例4: main
int main(int argc, char **argv)
{
int j;
int count = argc > 1 ? atoi(argv[1]) : 100;
printf("Testing time slice and mutexes, impl: %s\n",
(sthread_get_impl() == STHREAD_PTHREAD_IMPL) ? "pthread" : "user");
sthread_init();
if (sthread_create(thread_1, (void*)count, 1) == NULL) {
printf("sthread_create failed\n");
exit(1);
}
if (sthread_create(thread_2, (void*)count, 1) == NULL) {
printf("sthread_create failed\n");
exit(1);
}
printf("created two threads\n");
printf("if this is the last line of output, time slices aren't working!\n");
while(!t1_complete || !t2_complete);
printf("PASSED\n");
return 0;
}
示例5: main
int main(void)
{
printf("executing main function yeasss!!!!!!!\n");
sthread_t p,q,r;
sthread_mutex_init(&m);
sthread_create(&p,f1,NULL);
sthread_create(&q,f2,NULL);
sthread_create(&r,f3,NULL);
sthread_join(-1);
printf("\nmain finished ans: %d \n",sum);
return 0;
}
示例6: main
/*
* The main function starts the two producers and the consumer,
* the starts the thread scheduler.
*/
int main(int argc, char **argv) {
queue = new_bounded_buffer(DEFAULT_BUFFER_LENGTH);
sthread_create(producer, (void *) 0);
sthread_create(producer, (void *) 1);
sthread_create(consumer, (void *) 0);
/*
* Start the thread scheduler. By default, the timer is
* not started. Change the argument to 1 to start the timer.
*/
sthread_start(1);
return 0;
}
示例7: main
/*
* Runs four different threads that return at different times in order
* to ensure that they all terminate properly without error.
*/
int main(int argc, char **argv) {
int a = 1;
int b = 2;
int c = 3;
int d = 4;
/* Running threads */
sthread_create(test, &a);
sthread_create(test, &b);
sthread_create(test, &c);
sthread_create(test, &d);
sthread_start();
return 0;
}
示例8: main
int main(int argc, char **argv)
{
void *ret;
int i;
printf("Testing sthreads, impl: %s\n",
(sthread_get_impl() == STHREAD_PTHREAD_IMPL) ? "pthread" : "user");
sthread_init();
mon1 = sthread_monitor_init();
mon2 = sthread_monitor_init();
if (sthread_create(thread0, (void*)1, 10) == NULL) {
printf("sthread_create failed\n");
exit(-1);
}
sthread_monitor_enter(mon1);
for (i = 0; i < NUMBER; i++){
if ((thr[i] = sthread_create(thread1, (void*)i, 10)) == NULL) {
printf("sthread_create failed\n");
exit(-1);
}
sthread_yield();
}
for (i = 0; i < NUMBER; i++){
sthread_monitor_wait(mon1);
}
printf("in main\n");
sthread_monitor_exit(mon1);
sthread_sleep(10000);
sthread_monitor_enter(mon2);
sthread_monitor_signalall(mon2);
sthread_monitor_exit(mon2);
for (i = 0; i < NUMBER; i++){
sthread_join(thr[i], &ret);
}
printf("\nSUCCESS in creating %i threads\n", NUMBER);
printf("out main\n");
return 0;
}
示例9: rarch_main_data_thread_init
static void rarch_main_data_thread_init(void)
{
data_runloop_t *runloop = rarch_main_data_get_ptr();
if (!runloop)
return;
runloop->lock = slock_new();
runloop->cond_lock = slock_new();
runloop->overlay_lock = slock_new();
runloop->cond = scond_new();
runloop->thread = sthread_create(data_thread_loop, runloop);
if (!runloop->thread)
goto error;
slock_lock(runloop->lock);
runloop->thread_inited = true;
runloop->alive = true;
runloop->thread_code = THREAD_CODE_ALIVE;
slock_unlock(runloop->lock);
return;
error:
slock_free(runloop->lock);
slock_free(runloop->cond_lock);
slock_free(runloop->overlay_lock);
scond_free(runloop->cond);
}
示例10: main
int main(int argc, char **argv)
{
int i;
long ret;
sthread_t testers[NTHREADS];
srand(0); /* init the workload generator */
cacheinit(); /* init the buffer */
/* init blocks */
for (i = 0; i < NBLOCKS; i++) {
memcpy(blockData[i], (char *) &i, BLOCKSIZE);
}
/* start the testers */
for(i = 0; i < NTHREADS; i++) {
sthread_create(&(testers[i]), &tester, i);
}
/* wait for everyone to finish */
for(i = 0; i < NTHREADS; i++) {
ret = sthread_join(testers[i]);
}
printf("Main thread done.\n");
return ret;
}
示例11: main
int main(int argc, char **argv)
{
int checks;
printf("Testing sthread_mutex_*, impl: %s\n",
(sthread_get_impl() == STHREAD_PTHREAD_IMPL) ? "pthread" : "user");
sthread_init();
mutex = sthread_mutex_init();
sthread_mutex_lock(mutex);
if (sthread_create(thread_start, (void*)1, 1) == NULL) {
printf("sthread_create failed\n");
exit(1);
}
/* Wait until the other thread has at least started,
* to give it a chance at getting through the mutex incorrectly. */
while (ran_thread == 0) {
sthread_yield();
}
sthread_dump();
/* The other thread has run, but shouldn't have been
* able to affect counter (note that this is not a great test
* for preemptive scheduler, since the other thread's sequence
* is not atomic). */
assert(counter == 0);
/* This should let the other thread run at some point. */
sthread_mutex_unlock(mutex);
/* Allow up to 100 checks in case the scheduler doesn't
* decide to run the other thread for a really long time. */
checks = 100;
while (checks > 0) {
sthread_mutex_lock(mutex);
if (counter != 0) {
/* The other thread ran, got the lock,
* and incrmented the counter: test passes. */
checks = -1;
} else {
checks--;
}
sthread_mutex_unlock(mutex);
/* Nudge the scheduler to run the other thread: */
sthread_yield();
}
if (checks == -1) {
printf("sthread_mutex passed\n");
} else {
printf("*** sthread_mutex failed\n");
}
sthread_mutex_free(mutex);
return 0;
}
示例12: main
int main(int argc, char **argv) {
int arg = 1;
printf("Testing sthread_mutex_*, impl: %s\n",
(sthread_get_impl() == STHREAD_PTHREAD_IMPL) ? "pthread" : "user");
sthread_init();
mon = sthread_monitor_init();
sthread_monitor_enter(mon);
if (sthread_create(thread_start, (void*)&arg, 1) == NULL) {
printf("sthread_create failed\n");
exit(1);
}
printf("thread principal vai bloquear-se\n");
sthread_monitor_wait(mon);
printf("thread principal desbloqueada\n");
i = 2;
printf("i=2\n");
sthread_monitor_exit(mon);
if (i==2) {
printf("\nSUCESSO!\n");
} else {
printf("\nteste falhado...\n");
}
return 1;
}
示例13: sizeof
async_job_t *async_job_new(void)
{
async_job_t *ajob = (async_job_t*)calloc(1, sizeof(*ajob));
if (!ajob)
return NULL;
ajob->lock = slock_new();
if (!ajob->lock)
goto error;
ajob->sem = ssem_new(0);
if (!ajob->sem)
goto error;
ajob->thread = sthread_create(async_job_processor, (void*)ajob);
if (!ajob->thread)
goto error;
return ajob;
error:
if (ajob->lock)
slock_free(ajob->lock);
ajob->lock = NULL;
if (ajob->sem)
ssem_free(ajob->sem);
if (ajob)
free((void*)ajob);
return NULL;
}
示例14: rarch_main_data_thread_init
static void rarch_main_data_thread_init(void)
{
if (!g_data_runloop.thread_inited)
return;
g_data_runloop.lock = slock_new();
g_data_runloop.cond_lock = slock_new();
g_data_runloop.cond = scond_new();
#ifdef HAVE_OVERLAY
rarch_main_data_overlay_thread_init();
#endif
g_data_runloop.thread = sthread_create(data_thread_loop, &g_data_runloop);
if (!g_data_runloop.thread)
goto error;
slock_lock(g_data_runloop.lock);
g_data_runloop.thread_inited = true;
g_data_runloop.alive = true;
g_data_runloop.thread_code = THREAD_CODE_ALIVE;
slock_unlock(g_data_runloop.lock);
return;
error:
data_runloop_thread_deinit();
}
示例15: thread_init
static bool thread_init(thread_video_t *thr, const video_info_t *info, const input_driver_t **input,
void **input_data)
{
thr->lock = slock_new();
thr->alpha_lock = slock_new();
thr->frame.lock = slock_new();
thr->cond_cmd = scond_new();
thr->cond_thread = scond_new();
thr->input = input;
thr->input_data = input_data;
thr->info = *info;
thr->alive = true;
thr->focus = true;
size_t max_size = info->input_scale * RARCH_SCALE_BASE;
max_size *= max_size;
max_size *= info->rgb32 ? sizeof(uint32_t) : sizeof(uint16_t);
thr->frame.buffer = (uint8_t*)malloc(max_size);
if (!thr->frame.buffer)
return false;
memset(thr->frame.buffer, 0x80, max_size);
thr->target_frame_time = (retro_time_t)roundf(1000000LL / g_settings.video.refresh_rate);
thr->last_time = rarch_get_time_usec();
thr->thread = sthread_create(thread_loop, thr);
if (!thr->thread)
return false;
thread_send_cmd(thr, CMD_INIT);
thread_wait_reply(thr, CMD_INIT);
return thr->cmd_data.b;
}