本文整理汇总了C++中cond_init函数的典型用法代码示例。如果您正苦于以下问题:C++ cond_init函数的具体用法?C++ cond_init怎么用?C++ cond_init使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cond_init函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: main
/**
* Creates a case in which two threads will be racing to write one variable. Exected
* x will not be equal to actual x for a large enough loop unless there are locks.
*/
int main(int argc, char *argv[])
{
//Create 2 new threads.
if(argc != 3){
printf(2, "Usage: condtest <loop count> <num consumers>\n");
exit();
}
int pid;
loops = atoi(argv[1]);
numconsumers = atoi(argv[2]);
//initialize locks and condition variables
mutex_init(&mutex);
cond_init(&empty);
cond_init(&full);
//create one producer
pid = thread_create(&producer, (void *)"A"); //Thread 1: Add 1 to x
printf(2, "Parent created producer with pid %d.\n", pid);
int i;
//create x number of consumers
for (i = 0; i < numconsumers; i++){
pid = thread_create(&consumer, 0);
mutex_lock(&print);
printf(2, "Created consumer %d with pid %d.\n", i, pid);
mutex_unlock(&print);
}
//wait for children
for(i = 0; i < numconsumers+1; i++){
thread_wait();
}
exit();
}
开发者ID:jakefriedman,项目名称:cs637,代码行数:39,代码来源:condtest.c
示例2: cache_init
void
cache_init (void)
{
int i;
for (i = 0; i < CACHE_SIZE; i++)
{
lock_init (&block_cache[i].lock);
cond_init (&block_cache[i].r_w_done);
block_cache[i].old_sector = -1;
block_cache[i].sector = -1;
}
//first block is preallocated for the free map.
// it will not be evicted
block_cache[0].sector = 0;
block_cache[0].in_use = true;
block_cache[0].IO_needed = true;
cache_hand = 0;
lock_init (&cache_lock);
list_init (&read_ahead_queue);
lock_init (&read_ahead_lock);
cond_init (&read_ahead_go);
thread_create ("write-behind", PRI_DEFAULT, write_behind_func, NULL);
thread_create ("read_ahead", PRI_DEFAULT, read_ahead_func, NULL);
}
开发者ID:jamesbw,项目名称:CS140_W11-12,代码行数:29,代码来源:cache.c
示例3: rwlock_init
/* readers/writer lock function for SunOS 4.1.x added by H.Nakagaki */
int rwlock_init(rwlock_t *rw, int c, void *d)
{
mutex_init(&(rw->lock), 0, 0);
cond_init(&(rw->r_cond), &(rw->lock));
cond_init(&(rw->w_cond), &(rw->lock));
rw->readers = 0;
}
开发者ID:HiroyukiMikita,项目名称:EusLisp,代码行数:8,代码来源:mthread_sunos4.c
示例4: init_file_synch
static void init_file_synch (struct file_synch_status *fss) {
lock_init (&fss->lock);
lock_init (&fss->dir_lock);
fss->writers_waiting = 0;
fss->readers_running = 0;
cond_init (&fss->read_cond);
cond_init (&fss->write_cond);
}
开发者ID:samath,项目名称:140-v2,代码行数:8,代码来源:file-map.c
示例5: init_producer_consumer
/*
* Initializes the producer and consumer
* monitor variables
*/
void
init_producer_consumer(void) {
/* monitor lock */
lock_init(&mutex);
/* buffer conditions */
cond_init(¬_empty);
cond_init(¬_full);
}
开发者ID:jsquaredlau,项目名称:os11-pintos,代码行数:14,代码来源:producer-consumer.c
示例6: main
int main(void)
{
report_start(START_CMPLT);
//assuredly_misbehave((rand() % 521) % MISBEHAVE_MAX);
misbehave(BGND_BRWN >> FGND_CYAN); // for landslide
ERR(thr_init(STACK_SIZE));
ERR(mutex_init(&lock1));
ERR(mutex_init(&lock2));
ERR(cond_init(&cvar1));
ERR(cond_init(&cvar2));
ERR(thr_create(thread1, NULL));
report_misc("thread1 created");
/* Wait for thread1 to get to sleep on cvar1. */
mutex_lock(&lock1);
while (!slept1) {
mutex_unlock(&lock1);
thr_yield(-1);
mutex_lock(&lock1);
}
/* Indicate that we are about to signal */
signaled1 = 1;
mutex_unlock(&lock1);
/* Signal. Note that we know for sure that thread1 is asleep on
* cvar1 (assuming correct cond vars and mutexes...) */
cond_signal(&cvar1);
report_misc("cvar1 signaled");
//sleep(10);
/* Now do it all again for the second set of things. */
/* Wait for thread1 to get to sleep on cvar2. */
mutex_lock(&lock2);
while (!slept2) {
mutex_unlock(&lock2);
thr_yield(-1);
mutex_lock(&lock2);
}
/* Indicate that we are about to signal */
signaled2 = 1;
mutex_unlock(&lock2);
/* Signal. Note that we know for sure that thread1 is asleep on
* cvar1 (assuming correct cond vars and mutexes...) */
cond_signal(&cvar2);
report_misc("cvar2 signaled");
/* We report success from the other thread. */
return 0;
}
开发者ID:bblum,项目名称:landslide,代码行数:55,代码来源:paraguay.c
示例7: reaction_init
void reaction_init(struct reaction *reaction)
{
reaction->new_h_arrival = malloc(sizeof(struct condition));
reaction->reaction_occurred_h = malloc(sizeof(struct condition));
reaction->lck = malloc(sizeof(struct lock));
cond_init(reaction->new_h_arrival);
cond_init(reaction->reaction_occurred_h);
lock_init(reaction->lck);
reaction->h_atoms = 0;
}
开发者ID:gilsho,项目名称:os0,代码行数:11,代码来源:reaction.c
示例8: rwlock_init
/** @brief init a rwlock
*
* This function should initialize the lock pointed
* to by rwlock. Effects of using a lock before it has been initialized may be
* undefined. This function returns zero on success and a number less than
* zero on error.
*
* @para rwlock:
* @return error or success
**/
int rwlock_init(rwlock_t *rwlock)
{
rwlock->rd_cnt= 0;
rwlock->wr_cnt= 0;
mutex_init(&rwlock->rdcnt_mutex);
mutex_init(&rwlock->wrcnt_mutex);
cond_init(&rwlock->rd_cond);
cond_init(&rwlock->wr_cond);
cond_init(&rwlock->writer_cond);
return OK;
}
开发者ID:HaroldLee,项目名称:Rome2,代码行数:22,代码来源:rwlock.c
示例9: postfork1_child_tpool
void
postfork1_child_tpool(void)
{
pthread_t my_tid = pthread_self();
tpool_t *tpool;
tpool_job_t *job;
/*
* All of the thread pool workers are gone, except possibly
* for the current thread, if it is a thread pool worker thread.
* Retain the thread pools, but make them all empty. Whatever
* jobs were queued or running belong to the parent process.
*/
top:
if ((tpool = thread_pools) == NULL)
return;
do {
tpool_active_t *activep;
(void) mutex_init(&tpool->tp_mutex, USYNC_THREAD, NULL);
(void) cond_init(&tpool->tp_busycv, USYNC_THREAD, NULL);
(void) cond_init(&tpool->tp_workcv, USYNC_THREAD, NULL);
(void) cond_init(&tpool->tp_waitcv, USYNC_THREAD, NULL);
for (job = tpool->tp_head; job; job = tpool->tp_head) {
tpool->tp_head = job->tpj_next;
lfree(job, sizeof (*job));
}
tpool->tp_tail = NULL;
tpool->tp_njobs = 0;
for (activep = tpool->tp_active; activep;
activep = activep->tpa_next) {
if (activep->tpa_tid == my_tid) {
activep->tpa_next = NULL;
break;
}
}
tpool->tp_idle = 0;
tpool->tp_current = 0;
if ((tpool->tp_active = activep) != NULL)
tpool->tp_current = 1;
tpool->tp_flags &= ~TP_WAIT;
if (tpool->tp_flags & (TP_DESTROY | TP_ABANDON)) {
tpool->tp_flags &= ~TP_DESTROY;
tpool->tp_flags |= TP_ABANDON;
if (tpool->tp_current == 0) {
delete_pool(tpool);
goto top; /* start over */
}
}
} while ((tpool = tpool->tp_forw) != thread_pools);
}
开发者ID:andreiw,项目名称:polaris,代码行数:52,代码来源:thread_pool.c
示例10: bounded_buffer_init
void bounded_buffer_init(bounded_buffer_t *b, size_t size) {
b->buffer = (void **)mem_calloc(size, sizeof(void *));
b->size = size;
b->count = 0;
b->head = 0;
b->tail = 0;
mutex_init(&b->mutex);
cond_init(&b->empty);
cond_init(&b->fill);
b->done = 0;
b->workers = 0;
mutex_init(&b->worker_mutex);
}
开发者ID:malichan,项目名称:cs537-project,代码行数:13,代码来源:crawler.c
示例11: o_conInit
o_con_t o_conInit(int dummy) {
o_con_t c;
c = (o_con_t)malloc( sizeof(cond_t) );
cond_init( c, USYNC_THREAD, NULL );
return c;
}
开发者ID:aixp,项目名称:ethzoberonmirror,代码行数:7,代码来源:Threads.solaris.c
示例12: strlen
Thread::Thread( char *name, void *context, void *(*action)(void *) )
{
m_name = new char[ strlen(name) + 1 ];
strcpy( m_name, name );
m_context = context;
m_action = action;
// lock the registry ... add this thread to the registry
if ( Thread::count == 0 ) {
if ( mutex_init( &thread_mtx, USYNC_THREAD, NULL ) != 0 ) {
printf( "Thread init fails: thread_mutex could not be created.");
}
if ( mutex_init( &barrier_mtx, USYNC_THREAD, NULL ) != 0 ) {
printf( "Thread init fails: barrier_mutex could not be created.");
}
if ( cond_init( &barrier_cv, USYNC_THREAD, NULL ) != 0 ) {
printf( "Thread init fails: condition var could not be created.");
}
barrier_count = 0;
}
if ( mutex_lock( &thread_mtx ) != 0 ) {
printf( "Thread init fails: thread_mutex not allocated" );
}
Thread::thread_count++;
m_id = Thread::count++;
Thread::registry[m_id] = this;
if ( mutex_unlock( &thread_mtx ) != 0 ) {
printf( "Thread init fails: thread_mutex could not unlock ");
}
m_procid = (processorid_t) -1;
}
开发者ID:dberc,项目名称:tpzsimul.gems,代码行数:31,代码来源:Thread.C
示例13: alloc_group
/* allocate and initialize group */
static vntsd_group_t *
alloc_group(vntsd_t *vntsdp, char *group_name, uint64_t tcp_port)
{
vntsd_group_t *groupp;
/* allocate group */
groupp = (vntsd_group_t *)malloc(sizeof (vntsd_group_t));
if (groupp == NULL) {
vntsd_log(VNTSD_ERR_NO_MEM, "alloc_group");
return (NULL);
}
/* initialize group */
bzero(groupp, sizeof (vntsd_group_t));
(void) mutex_init(&groupp->lock, USYNC_THREAD|LOCK_ERRORCHECK, NULL);
(void) cond_init(&groupp->cvp, USYNC_THREAD, NULL);
if (group_name != NULL) {
(void) memcpy(groupp->group_name, group_name, MAXPATHLEN);
}
groupp->tcp_port = tcp_port;
groupp->listen_tid = (thread_t)-1;
groupp->sockfd = (thread_t)-1;
groupp->vntsd = vntsdp;
D1(stderr, "[email protected]%d [email protected]%lld:%s\n", thr_self(), groupp->tcp_port,
groupp->group_name);
return (groupp);
}
开发者ID:andreiw,项目名称:polaris,代码行数:33,代码来源:vntsdvcc.c
示例14: worker_init
/*===========================================================================*
* worker_init *
*===========================================================================*/
PUBLIC void worker_init(struct worker_thread *wp)
{
/* Initialize worker thread */
if (!init) {
threads_init();
if (mthread_attr_init(&tattr) != 0)
panic("failed to initialize attribute");
if (mthread_attr_setstacksize(&tattr, TH_STACKSIZE) != 0)
panic("couldn't set default thread stack size");
if (mthread_attr_setdetachstate(&tattr, MTHREAD_CREATE_DETACHED) != 0)
panic("couldn't set default thread detach state");
pending = 0;
init = 1;
}
ASSERTW(wp);
wp->w_job.j_func = NULL; /* Mark not in use */
wp->w_next = NULL;
if (mutex_init(&wp->w_event_mutex, NULL) != 0)
panic("failed to initialize mutex");
if (cond_init(&wp->w_event, NULL) != 0)
panic("failed to initialize conditional variable");
if (mthread_create(&wp->w_tid, &tattr, worker_main, (void *) wp) != 0)
panic("unable to start thread");
yield();
}
开发者ID:vivekp,项目名称:minix-1,代码行数:30,代码来源:worker.c
示例15: nscd_wait
int
nscd_wait(nsc_ctx_t *ctx, nsc_db_t *nscdb, nsc_entry_t *entry)
{
waiter_t mywait;
waiter_t *wchan = &nscdb->db_wait;
(void) cond_init(&(mywait.w_waitcv), USYNC_THREAD, 0);
mywait.w_key = entry;
mywait.w_signaled = 0;
mywait.w_next = wchan->w_next;
mywait.w_prev = wchan;
if (mywait.w_next)
mywait.w_next->w_prev = &mywait;
wchan->w_next = &mywait;
(void) mutex_lock(&ctx->stats_mutex);
ctx->stats.wait_count++;
(void) mutex_unlock(&ctx->stats_mutex);
while (!mywait.w_signaled)
(void) cond_wait(&(mywait.w_waitcv), &nscdb->db_mutex);
if (mywait.w_prev)
mywait.w_prev->w_next = mywait.w_next;
if (mywait.w_next)
mywait.w_next->w_prev = mywait.w_prev;
return (0);
}
开发者ID:AlainODea,项目名称:illumos-gate,代码行数:27,代码来源:nscd_wait.c
示例16: cookie_cache_init
void cookie_cache_init(struct cookie_cache *c) {
cookie_cache_state_init(&c->current);
cookie_cache_state_init(&c->old);
c->swap_time = poller_now;
mutex_init(&c->lock);
cond_init(&c->cond);
}
开发者ID:Vocalocity,项目名称:rtpengine,代码行数:7,代码来源:cookie_cache.c
示例17: _pthread_cond_init
int
_pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *cond_attr)
{
*cond = NULL;
return (cond_init(cond, cond_attr));
}
开发者ID:AhmadTux,项目名称:freebsd,代码行数:7,代码来源:thr_cond.c
示例18: control_start
static struct sml_control *
control_start(struct frame_stack_range *range)
{
struct sml_control *control;
assert(tlv_get_or_init(current_control) == NULL);
control = xmalloc(sizeof(struct sml_control));
#ifndef WITHOUT_MULTITHREAD
atomic_init(&control->state, ACTIVE(ASYNC));
mutex_init(&control->inactive_wait_lock);
cond_init(&control->inactive_wait_cond);
#endif /* !WITHOUT_MULTITHREAD */
control->frame_stack = range;
range->next = NULL;
control->thread_local_heap = NULL;
control->exn_object = NULL;
tlv_set(current_control, control);
control_register(control);
/* thread local heap is allocated after the control is set up. */
control->thread_local_heap = sml_heap_mutator_init();
return control;
}
开发者ID:eldesh,项目名称:smlsharp,代码行数:25,代码来源:control.c
示例19: xcalloc
struct cache *cache_new(struct options *opts) {
struct cache *c;
c = xcalloc(1, sizeof(*c));
rwlock_init(&c->clock_lock);
mutex_init(&c->mtx);
cond_init(&c->condvar);
c->clock = cpair_list_new();
c->table = cpair_htable_new();
c->opts = opts;
gettime(&c->last_checkpoint);
c->flusher = cron_new(flusher_cb, opts->cache_flush_period_ms);
if (cron_start(c->flusher, (void*)c) != 1) {
__PANIC("%s",
"flushe cron start error, will exit");
goto ERR;
}
return c;
ERR:
xfree(c);
return NULL;
}
开发者ID:tonicbupt,项目名称:nessDB,代码行数:25,代码来源:cache.c
示例20: simple_condwait
void simple_condwait(void)
{
unsigned long long start;
mutex_t mutex;
cond_t cond;
struct cond_mutex cm = {
.mutex = &mutex,
.cond = &cond,
};
thread_t cond_signaler_tid;
fprintf(stderr, "%s\n", __FUNCTION__);
check("mutex_init", mutex_init(&mutex, PTHREAD_MUTEX_DEFAULT, 0), 0);
check("cond_init", cond_init(&cond, 0), 0);
check("mutex_lock", mutex_lock(&mutex), 0);
check("thread_spawn",
thread_spawn(&cond_signaler_tid, 2, cond_signaler, &cm), 0);
thread_msleep(11);
start = rt_timer_tsc();
check("cond_wait", cond_wait(&cond, &mutex, XN_INFINITE), 0);
check_sleep("cond_wait", start);
thread_msleep(10);
check("mutex_unlock", mutex_unlock(&mutex), 0);
check("thread_join", thread_join(cond_signaler_tid), 0);
check("mutex_destroy", mutex_destroy(&mutex), 0);
check("cond_destroy", cond_destroy(&cond), 0);
}
开发者ID:xxha,项目名称:xenomai-2.5.6,代码行数:29,代码来源:cond-torture.c
注:本文中的cond_init函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论