本文整理汇总了C++中pthread_yield函数的典型用法代码示例。如果您正苦于以下问题:C++ pthread_yield函数的具体用法?C++ pthread_yield怎么用?C++ pthread_yield使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pthread_yield函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: RTDECL
RTDECL(bool) RTThreadYield(void)
{
#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
uint64_t u64TS = ASMReadTSC();
#endif
#ifdef RT_OS_DARWIN
pthread_yield_np();
#elif defined(RT_OS_SOLARIS) || defined(RT_OS_HAIKU)
sched_yield();
#else
pthread_yield();
#endif
#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
u64TS = ASMReadTSC() - u64TS;
bool fRc = u64TS > 1500;
LogFlow(("RTThreadYield: returning %d (%llu ticks)\n", fRc, u64TS));
#else
bool fRc = true; /* PORTME: Add heuristics for determining whether the cpus was yielded. */
#endif
return fRc;
}
开发者ID:bayasist,项目名称:vbox,代码行数:21,代码来源:thread2-posix.cpp
示例2: produce_function1
void* produce_function1 ( void *ptr )
{
RingBufferProducer* p_producer = (RingBufferProducer *) ptr; /* type cast to a
pointer to thdata */
struct timespec ts;
ts.tv_sec = 0;
ts.tv_nsec = 1;
unsigned char v[64];
for (unsigned long i = 1 ; i <= N_ITERS; i++)
{
*((unsigned long*)v) = i;
while (p_producer->write(v, 64) != 64)
pthread_yield();
// if (i % 10000 == 0)
// printf("%d\n", i);
}
fprintf(stderr, "producer is done\n");
}
开发者ID:igmor,项目名称:ringbuffer,代码行数:21,代码来源:main.cpp
示例3: func_noise
void* func_noise(void* arg)
{
Thread* pthr = (Thread*)arg;
int rc, i, j, policy, tid = gettid();
struct sched_param schedp;
cpu_set_t mask;
CPU_ZERO(&mask);
CPU_SET(0, &mask);
rc = sched_setaffinity(0, sizeof(mask), &mask);
if (rc < 0) {
printf("Thread %d: Can't set affinity: %d %s\n", tid, rc, strerror(rc));
exit(-1);
}
rc = sched_getaffinity(0, sizeof(mask), &mask);
printf("Noise Thread started %d on CPU %ld\n", pthr->priority, (long)mask.__bits[0]);
pthread_getschedparam(pthr->pthread, &policy, &schedp);
while (1) {
sleep(1);
printf("Noise Thread running %d\n", pthr->priority);
for (i = 0; i < 10000; i++) {
if ((i % 100) == 0) {
sched_getparam(tid, &schedp);
policy = sched_getscheduler(tid);
printf("Noise Thread %d(%d) loop %d pthread pol %d pri %d\n", tid, pthr->priority, i, policy, schedp.sched_priority);
fflush(NULL);
}
pthr->id++;
for (j = 0; j < 5000; j++) {
pthread_mutex_lock(&(pthr->mutex));
pthread_mutex_unlock(&(pthr->mutex));
}
}
pthread_yield();
}
return NULL;
}
开发者ID:shubmit,项目名称:shub-ltp,代码行数:40,代码来源:testpi-3.c
示例4: do_send_err
void do_send_err(int len)
{
int ret;
struct fi_cq_tagged_entry s_cqe;
struct fi_cq_err_entry err_cqe;
ssize_t sz;
uint64_t s[NUMEPS] = {0}, r[NUMEPS] = {0}, s_e[NUMEPS] = {0};
uint64_t r_e[NUMEPS] = {0};
rdm_sr_init_data(source, len, 0xab);
rdm_sr_init_data(target, len, 0);
sz = fi_send(ep[0], source, len, loc_mr[0], gni_addr[1], target);
cr_assert_eq(sz, 0);
while ((ret = fi_cq_read(msg_cq[0], &s_cqe, 1)) == -FI_EAGAIN) {
pthread_yield();
}
cr_assert_eq(ret, -FI_EAVAIL);
ret = fi_cq_readerr(msg_cq[0], &err_cqe, 0);
cr_assert_eq(ret, 1);
cr_assert((uint64_t)err_cqe.op_context == (uint64_t)target,
"Bad error context");
cr_assert(err_cqe.flags == (FI_MSG | FI_SEND));
cr_assert(err_cqe.len == 0, "Bad error len");
cr_assert(err_cqe.buf == 0, "Bad error buf");
cr_assert(err_cqe.data == 0, "Bad error data");
cr_assert(err_cqe.tag == 0, "Bad error tag");
cr_assert(err_cqe.olen == 0, "Bad error olen");
cr_assert(err_cqe.err == FI_ECANCELED, "Bad error errno");
cr_assert(err_cqe.prov_errno == GNI_RC_TRANSACTION_ERROR,
"Bad prov errno");
cr_assert(err_cqe.err_data == NULL, "Bad error provider data");
s_e[0] = 1;
rdm_sr_check_cntrs(s, r, s_e, r_e);
}
开发者ID:agontarek,项目名称:libfabric,代码行数:40,代码来源:rdm_sr.c
示例5: lf_alloc_put_pins
/*
Put pins back to a pinbox. Usually called via lf_alloc_put_pins() or
lf_hash_put_pins().
DESCRIPTION
empty the purgatory (XXX deadlock warning below!),
push LF_PINS structure to a stack
*/
void _lf_pinbox_put_pins(LF_PINS *pins)
{
LF_PINBOX *pinbox= pins->pinbox;
uint32 top_ver, nr;
nr= pins->link;
#ifndef DBUG_OFF
{
/* This thread should not hold any pin. */
int i;
for (i= 0; i < LF_PINBOX_PINS; i++)
DBUG_ASSERT(pins->pin[i] == 0);
}
#endif /* DBUG_OFF */
/*
XXX this will deadlock if other threads will wait for
the caller to do something after _lf_pinbox_put_pins(),
and they would have pinned addresses that the caller wants to free.
Thus: only free pins when all work is done and nobody can wait for you!!!
*/
while (pins->purgatory_count)
{
_lf_pinbox_real_free(pins);
if (pins->purgatory_count)
{
my_atomic_rwlock_wrunlock(&pins->pinbox->pinarray.lock);
pthread_yield();
my_atomic_rwlock_wrlock(&pins->pinbox->pinarray.lock);
}
}
top_ver= pinbox->pinstack_top_ver;
do
{
pins->link= top_ver % LF_PINBOX_MAX_PINS;
} while (!my_atomic_cas32((int32 volatile*) &pinbox->pinstack_top_ver,
(int32*) &top_ver,
top_ver-pins->link+nr+LF_PINBOX_MAX_PINS));
return;
}
开发者ID:0x00xw,项目名称:mysql-2,代码行数:48,代码来源:lf_alloc-pin.c
示例6: pthread_mutex_lock
static void *thread_func(void *parameter)
{
int id = (int)parameter;
int ndx = id - 1;
int i;
for (nloops[ndx] = 0; nloops[ndx] < NLOOPS; nloops[ndx]++)
{
int status = pthread_mutex_lock(&mut);
if (status != 0)
{
printf("ERROR thread %d: pthread_mutex_lock failed, status=%d\n",
id, status);
}
if (my_mutex == 1)
{
printf("ERROR thread=%d: "
"my_mutex should be zero, instead my_mutex=%d\n",
id, my_mutex);
nerrors[ndx]++;
}
my_mutex = 1;
for (i = 0; i < 10; i++)
{
pthread_yield();
}
my_mutex = 0;
status = pthread_mutex_unlock(&mut);
if (status != 0)
{
printf("ERROR thread %d: pthread_mutex_unlock failed, status=%d\n",
id, status);
}
}
pthread_exit(NULL);
return NULL; /* Non-reachable -- needed for some compilers */
}
开发者ID:0919061,项目名称:PX4NuttX,代码行数:40,代码来源:mutex.c
示例7: do_read
static void do_read(int len)
{
ssize_t sz;
uint64_t old_w_cnt, new_w_cnt;
uint64_t old_r_cnt, new_r_cnt;
#define READ_CTX 0x4e3dda1aULL
init_data(source, len, 0);
init_data(target, len, 0xad);
old_w_cnt = fi_cntr_read(write_cntr);
cr_assert(old_w_cnt >= 0);
old_r_cnt = fi_cntr_read(read_cntr);
cr_assert(old_r_cnt >= 0);
sz = fi_read(ep[0], source, len,
loc_mr, gni_addr[1], (uint64_t)target, mr_key,
(void *)READ_CTX);
cr_assert_eq(sz, 0);
do {
new_r_cnt = fi_cntr_read(read_cntr);
cr_assert(new_r_cnt >= 0);
if (new_r_cnt == (old_r_cnt + 1))
break;
pthread_yield();
} while (1);
cr_assert(check_data(source, target, len), "Data mismatch");
new_w_cnt = fi_cntr_read(write_cntr);
cr_assert(new_w_cnt >= 0);
/*
* no fi_read called so old and new read cnts should be equal
*/
cr_assert(new_w_cnt == old_w_cnt);
}
开发者ID:ddurnov,项目名称:libfabric,代码行数:39,代码来源:cntr.c
示例8: defined
void thread::yield()
{
#if defined(BOOST_HAS_WINTHREADS)
Sleep(0);
#elif defined(BOOST_HAS_PTHREADS)
# if defined(BOOST_HAS_SCHED_YIELD)
int res = 0;
res = sched_yield();
assert(res == 0);
# elif defined(BOOST_HAS_PTHREAD_YIELD)
int res = 0;
res = pthread_yield();
assert(res == 0);
# else
xtime xt;
xtime_get(&xt, TIME_UTC);
sleep(xt);
# endif
#elif defined(BOOST_HAS_MPTASKS)
MPYield();
#endif
}
开发者ID:Albermg7,项目名称:boost,代码行数:22,代码来源:thread.cpp
示例9: SortedList_insert
/**
* SortedList_insert ... insert an element into a sorted list
*
*The specified element will be inserted in to
*the specified list, which will be kept sorted
*in ascending order based on associated keys
*
* @param SortedList_t *list ... header for the list
* @param SortedListElement_t *element ... element to be added to the list
*
* Note: if (opt_yield & INSERT_YIELD)
*call pthread_yield in middle of critical section
*/
void SortedList_insert(SortedList_t *list, SortedListElement_t *element){
SortedList_t *next = list->next;
SortedList_t *prev = list;
while(next != NULL){
if(strcmp(element->key, next->key) <= 0)
break;
prev = next;
next = next->next;
}
if(opt_yield & INSERT_YIELD){
pthread_yield();
}
element->prev = prev;
element->next = next;
prev->next = element;
if(next != NULL){
next->prev = element;
}
}
开发者ID:chrislciaba,项目名称:111-Projects,代码行数:35,代码来源:SortedList.c
示例10: execute_thread
void
execute_thread(void *c)
{
command_t command = (command_t) c;
pthread_mutex_lock(&d_mutex);
while(!is_runnable(pthread_self()))
{
pthread_mutex_unlock(&d_mutex);
pthread_yield();
pthread_mutex_lock(&d_mutex);
}
pthread_mutex_unlock(&d_mutex);
exec_command(c);
pthread_mutex_lock(&d_mutex);
pthread_mutex_lock(&tc_mutex);
thread_count--;
remove_dependencies(pthread_self());
pthread_mutex_unlock(&tc_mutex);
pthread_mutex_unlock(&d_mutex);
free(command);
pthread_exit(0);
}
开发者ID:aamoyg,项目名称:CS111,代码行数:22,代码来源:execute-command.c
示例11: printf
bool Skitt::start_animation()
{
if (!animation->open()) {
return false;
}
/* Have to get that first frame. */
if (!animation->next_frame()) {
return false;
}
if (!start_loading_files()) {
return false;
}
printf("Waiting for buffers to get a few frames...\n");
while (!screen->are_buffers_full(min_num_frames_load)) {
pthread_yield();
}
printf("Buffers have 100 frames. Starting the playback timer.\n");
if (!start_playback_loop()) {
return false;
}
return true;
}
开发者ID:fallrisk,项目名称:led_drapes,代码行数:22,代码来源:skitt.cpp
示例12: do_read_error
void do_read_error(int len)
{
int ret;
ssize_t sz;
struct fi_cq_tagged_entry cqe;
struct fi_cq_err_entry err_cqe;
init_data(source, len, 0);
init_data(target, len, 0xad);
sz = fi_read(ep[0], source, len,
loc_mr, gni_addr[1], (uint64_t)target, mr_key,
(void *)READ_CTX);
cr_assert_eq(sz, 0);
while ((ret = fi_cq_read(send_cq, &cqe, 1)) == -FI_EAGAIN) {
pthread_yield();
}
cr_assert_eq(ret, -FI_EAVAIL);
ret = fi_cq_readerr(send_cq, &err_cqe, 0);
cr_assert_eq(ret, 1);
cr_assert((uint64_t)err_cqe.op_context == (uint64_t)READ_CTX,
"Bad error context");
cr_assert(err_cqe.flags == (FI_RMA | FI_READ));
cr_assert(err_cqe.len == 0, "Bad error len");
cr_assert(err_cqe.buf == 0, "Bad error buf");
cr_assert(err_cqe.data == 0, "Bad error data");
cr_assert(err_cqe.tag == 0, "Bad error tag");
cr_assert(err_cqe.olen == 0, "Bad error olen");
cr_assert(err_cqe.err == FI_ECANCELED, "Bad error errno");
cr_assert(err_cqe.prov_errno == GNI_RC_TRANSACTION_ERROR,
"Bad prov errno");
cr_assert(err_cqe.err_data == NULL, "Bad error provider data");
rdm_rma_check_cntrs(0, 0, 0, 1);
}
开发者ID:RajKamal2013,项目名称:libfabric,代码行数:38,代码来源:rdm_rma.c
示例13: SortedList_insert
void SortedList_insert(SortedList_t *list, SortedListElement_t *element){
SortedListElement_t *previous=list;
while(previous->next!=NULL){
if(strcmp(previous->next->key,element->key)<=0)
previous=previous->next;
else break;
}
if(opt_yield&INSERT_YIELD) pthread_yield();//yield
if(previous->next!=NULL){
SortedListElement_t *successor=previous->next;
previous->next=element;
element->next=successor;
element->prev=previous;
successor->prev=element;
}
else{
previous->next=element;
element->prev=previous;
element->next=NULL;
}
return;
}
开发者ID:Lavender-Ding,项目名称:OperatingSystemsPrinciples,代码行数:23,代码来源:SortedList.c
示例14: while
void *producer_generate(void *handle) {
producer_thread_data_pt th_data = (producer_thread_data_pt) handle;
celix_status_t status = CELIX_SUCCESS;
int sampleRate;
th_data->running = true;
while (th_data->running && status == CELIX_SUCCESS) {
pthread_rwlock_rdlock(&th_data->throughputLock);
sampleRate = th_data->sampleRate;
pthread_rwlock_unlock(&th_data->throughputLock);
if (th_data->sampleRate > 0) {
status = producer_sendBursts(th_data, sampleRate);
status = producer_sendSamples(th_data, sampleRate);
}
pthread_yield();
}
return NULL;
}
开发者ID:NausJessy,项目名称:demonstrator,代码行数:23,代码来源:producer_impl.c
示例15: lookahead_cbuf
/* Lookahead in the circular buffer. Same rules and behavior as remove_cbuf,
except the cbuf->head pointer does not move. CAVEAT: the size of the
lookahead is assumed to be a small fraction of the buffer size
No "unget" is implemented. "unget" in a multithreaded environment such
as this would be potentially disastrous. Lookahead should provide a
reasonable alternative to "unget".
*/
int lookahead_cbuf(cbuf * buffer, buf_t * bytes, int count)
{
int j, phead, actual;
actual = 0;
pthread_mutex_lock(buffer->readlock);
phead = buffer->head;
for (j = phead; actual < count; j = (j + 1) % (buffer->bufsize)) {
while (j == (buffer->tail + 1) % (buffer->bufsize)) {
if (buffer->refcnt) {
pthread_yield();
} else {
pthread_mutex_unlock(buffer->readlock);
return (actual);
}
}
bytes[actual] = buffer->buf[j];
actual++;
phead = (phead + 1) % (buffer->bufsize);
}
pthread_mutex_unlock(buffer->readlock);
return (actual);
}
开发者ID:glocklueng,项目名称:WeatherStation,代码行数:31,代码来源:cbuf.c
示例16: get_event_file_path
// thread listening function
void *listen_event_file(void *arg)
{
int id_file = (int) *((int *) arg);
char * path_file = get_event_file_path(id_file);
printf("listen to %s\n",path_file);
int fd = open(path_file, O_RDONLY | O_NONBLOCK);
struct input_event ev;
while (found < 0)
{
int count = read(fd, &ev, sizeof(struct input_event));
if (ev.type == 1)
{
pthread_mutex_lock(&mutex_device);
found = id_file;
pthread_mutex_unlock(&mutex_device);
found_path_file = path_file;
}
pthread_yield();
}
pthread_exit(NULL);
}
开发者ID:Safe3,项目名称:BackdoorLinux,代码行数:24,代码来源:keylogger.c
示例17: __cilkrts_yield
COMMON_SYSDEP void __cilkrts_yield(void)
{
#if __APPLE__ || __FreeBSD__ || __VXWORKS__
// On MacOS, call sched_yield to yield quantum. I'm not sure why we
// don't do this on Linux also.
sched_yield();
#elif defined(__MIC__)
// On MIC, pthread_yield() really trashes things. Arch's measurements
// showed that calling _mm_delay_32() (or doing nothing) was a better
// option. Delaying 1024 clock cycles is a reasonable compromise between
// giving up the processor and latency starting up when work becomes
// available
_mm_delay_32(1024);
#elif defined(ANDROID)
// On Android, call sched_yield to yield quantum. I'm not sure why we
// don't do this on Linux also.
sched_yield();
#else
// On Linux, call pthread_yield (which in turn will call sched_yield)
// to yield quantum.
pthread_yield();
#endif
}
开发者ID:Detry322,项目名称:cilkrtl-sls,代码行数:23,代码来源:os-unix.c
示例18: SortedList_delete
/**
* SortedList_delete ... remove an element from a sorted list
*
* The specified element will be removed from whatever
* list it is currently in.
*
* Before doing the deletion, we check to make sure that
* next->prev and prev->next both point to this node
*
* @param SortedListElement_t *element ... element to be removed
*
* @return 0: element deleted successfully, 1: corrtuped prev/next pointers
*
* Note: if (opt_yield & DELETE_YIELD)
* call pthread_yield in middle of critical section
*/
int SortedList_delete( SortedListElement_t *element){
if (element == NULL)
return 1;
SortedListElement_t *q = element->next;
// middle of critical section
if (opt_yield & DELETE_YIELD)
pthread_yield();
SortedListElement_t *p = element->prev;
// Check for race conditions
if( (p->next != element) || (q->prev != element) )
return 1;
q->prev = p;
p->next = q;
element->next = NULL;
element->prev = NULL;
// free memory?
free(element);
return 0;
}
开发者ID:AndersonHuang95,项目名称:CS111,代码行数:39,代码来源:SortedList.c
示例19: sep_atomic_compwrite
void sep_atomic_compwrite(int index)
{
int ret;
ssize_t sz;
struct fi_cq_tagged_entry cqe = { (void *) -1, UINT_MAX, UINT_MAX,
(void *) -1, UINT_MAX, UINT_MAX };
uint64_t operand = SOURCE_DATA, op2 = TARGET_DATA;
uint64_t w[NUMEPS] = {0}, r[NUMEPS] = {0}, w_e[NUMEPS] = {0};
uint64_t r_e[NUMEPS] = {0};
/* u64 */
*((uint64_t *)source) = FETCH_SOURCE_DATA;
*((uint64_t *)target) = TARGET_DATA;
sz = fi_compare_atomic(tx_ep[0][index], &operand, 1, NULL, &op2, NULL,
source, loc_mr[0], rx_addr[index],
(uint64_t)target, mr_key[1], FI_UINT64,
FI_CSWAP, target);
cr_assert_eq(sz, 0, "fi_compare_atomic returned %ld (%s)", sz,
fi_strerror(-sz));
/* reset cqe */
cqe.op_context = cqe.buf = (void *) -1;
cqe.flags = cqe.len = cqe.data = cqe.tag = UINT_MAX;
while ((ret = fi_cq_read(tx_cq[0][index], &cqe, 1)) == -FI_EAGAIN) {
pthread_yield();
}
cr_assert_eq(ret, 1);
sep_check_tcqe(&cqe, target, FI_ATOMIC | FI_READ, 0);
r[0] = 1;
sep_check_cntrs(w, r, w_e, r_e);
ret = *((uint64_t *)target) == SOURCE_DATA;
cr_assert(ret, "Data mismatch");
ret = *((uint64_t *)source) == TARGET_DATA;
cr_assert(ret, "Fetch data mismatch");
}
开发者ID:francois-wellenreiter,项目名称:libfabric,代码行数:37,代码来源:sep.c
示例20: sep_inject_write
void sep_inject_write(int index, int len)
{
ssize_t sz;
int ret, i;
struct fi_cq_tagged_entry cqe;
sep_init_data(source, len, 0x33);
sep_init_data(target, len, 0);
sz = fi_inject_write(tx_ep[0][index], source, len,
rx_addr[index], (uint64_t)target, mr_key[1]);
cr_assert_eq(sz, 0, "fi_inject_write returned %ld (%s)", sz,
fi_strerror(-sz));
for (i = 0; i < len; i++) {
while (source[i] != target[i]) {
/* for progress */
ret = fi_cq_read(tx_cq[0][index], &cqe, 1);
cr_assert(ret == -FI_EAGAIN || ret == -FI_EAVAIL,
"Received unexpected event\n");
pthread_yield();
}
}
}
开发者ID:francois-wellenreiter,项目名称:libfabric,代码行数:24,代码来源:sep.c
注:本文中的pthread_yield函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论