本文整理汇总了C++中sem_create函数的典型用法代码示例。如果您正苦于以下问题:C++ sem_create函数的具体用法?C++ sem_create怎么用?C++ sem_create使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sem_create函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main (int argc, char *argv[])
{
printf ("Main INICIO\n") ;
task_init () ;
sem_create (&s1, 1) ;
sem_create (&s2, 0) ;
task_create (&a1, TaskA, "A1") ;
task_create (&a2, TaskA, " A2") ;
task_create (&b1, TaskB, " B1") ;
task_create (&b2, TaskB, " B2") ;
task_join (&a1) ;
sem_destroy (&s1) ;
sem_destroy (&s2) ;
task_join (&a2) ;
task_join (&b1) ;
task_join (&b2) ;
printf ("Main FIM\n") ;
task_exit (0) ;
exit (0) ;
}
示例2: inititems
static
void
inititems(void)
{
if (BrSem==NULL) {
BrSem = sem_create("BrSem", 3);
if (BrSem == NULL) {
panic("BrSem: sem_create failed\n");
}
}
if (doneSem==NULL) {
doneSem = sem_create("doneSem", 0);
if (doneSem == NULL) {
panic("synchtest: sem_create failed\n");
}
}
if (BrLock==NULL) {
BrLock = lock_create("BrLock");
if (BrLock == NULL) {
panic("BrLock: lock_create failed\n");
}
}
if (boyCV==NULL) {
boyCV = cv_create("boyCV");
if (boyCV == NULL) {
panic("boyCV: cv_create failed\n");
}
}
if (girlCV==NULL) {
girlCV = cv_create("girlCV");
if (girlCV == NULL) {
panic("girlCV: cv_create failed\n");
}
}
}
示例3: elves
int
elves(int nargs, char **args)
{
unsigned num_elves;
// if an argument is passed, use that as the number of elves
num_elves = 10;
if (nargs == 2) {
num_elves = atoi(args[1]);
}
// Suppress unused warnings. Remove these when finished.
(void) work;
(void) supervisor;
(void) elf;
(void) num_elves;
// TODO
print_lock = sem_create("print", 1);
elf_lock = sem_create("elf", num_elves);
complete_lock = sem_create("complete_lk", 1);
elf_complete = -1;
kprintf("Starting up Keebler Factory!\n");
supervisor(NULL, num_elves);
return 0;
}
示例4: config_lhd
/*
* Setup routine called by autoconf.c when an lhd is found.
*/
int
config_lhd(struct lhd_softc *lh, int lhdno)
{
char name[32];
/* Figure out what our name is. */
snprintf(name, sizeof(name), "lhd%d", lhdno);
/* Get a pointer to the on-chip buffer. */
lh->lh_buf = bus_map_area(lh->lh_busdata, lh->lh_buspos, LHD_BUFFER);
/* Create the semaphores. */
lh->lh_clear = sem_create("lhd-clear", 1);
if (lh->lh_clear == NULL) {
return ENOMEM;
}
lh->lh_done = sem_create("lhd-done", 0);
if (lh->lh_done == NULL) {
sem_destroy(lh->lh_clear);
lh->lh_clear = NULL;
return ENOMEM;
}
/* Set up the VFS device structure. */
lh->lh_dev.d_ops = &lhd_devops;
lh->lh_dev.d_blocks = bus_read_register(lh->lh_busdata, lh->lh_buspos,
LHD_REG_NSECT);
lh->lh_dev.d_blocksize = LHD_SECTSIZE;
lh->lh_dev.d_data = lh;
/* Add the VFS device structure to the VFS device list. */
return vfs_adddev(name, &lh->lh_dev, 1);
}
示例5: inititems
static
void
inititems(void)
{
if (testsem==NULL) {
testsem = sem_create("testsem", 2);
if (testsem == NULL) {
panic("synchtest: sem_create failed\n");
}
}
if (testlock==NULL) {
testlock = lock_create("testlock");
if (testlock == NULL) {
panic("synchtest: lock_create failed\n");
}
}
if (testcv==NULL) {
testcv = cv_create("testlock");
if (testcv == NULL) {
panic("synchtest: cv_create failed\n");
}
}
if (donesem==NULL) {
donesem = sem_create("donesem", 0);
if (donesem == NULL) {
panic("synchtest: sem_create failed\n");
}
}
}
示例6: createSemaphores
void createSemaphores(void) {
sem_create(smutex, 1);
sem_create(sage, 0);
sem_create(stob, 0);
sem_create(spap, 0);
sem_create(smat, 0);
}
示例7: kmalloc
static struct pipefs_vnode *pipefs_create_vnode(struct pipefs *fs, const char *name, stream_type type)
{
struct pipefs_vnode *v;
v = kmalloc(sizeof(struct pipefs_vnode));
if(v == NULL)
return NULL;
memset(v, 0, sizeof(struct pipefs_vnode));
v->id = atomic_add(&fs->next_vnode_id, 1);
v->name = kstrdup(name);
if(v->name == NULL)
goto err;
v->stream.type = type;
switch(type) {
case STREAM_TYPE_DIR:
v->stream.u.dir.dir_head = NULL;
v->stream.u.dir.jar_head = NULL;
if(mutex_init(&v->stream.u.dir.dir_lock, "pipefs_dir_lock") < 0)
goto err;
break;
case STREAM_TYPE_PIPE:
v->stream.u.pipe.buf = kmalloc(PIPE_BUFFER_LEN);
if(v->stream.u.pipe.buf == NULL)
goto err;
v->stream.u.pipe.buf_len = PIPE_BUFFER_LEN;
if(mutex_init(&v->stream.u.pipe.lock, "pipe_lock") < 0) {
kfree(v->stream.u.pipe.buf);
goto err;
}
v->stream.u.pipe.read_sem = sem_create(0, "pipe_read_sem");
if(v->stream.u.pipe.read_sem < 0) {
mutex_destroy(&v->stream.u.pipe.lock);
kfree(v->stream.u.pipe.buf);
goto err;
}
v->stream.u.pipe.write_sem = sem_create(1, "pipe_write_sem");
if(v->stream.u.pipe.write_sem < 0) {
sem_delete(v->stream.u.pipe.read_sem);
mutex_destroy(&v->stream.u.pipe.lock);
kfree(v->stream.u.pipe.buf);
goto err;
}
break;
}
return v;
err:
if(v->name)
kfree(v->name);
kfree(v);
return NULL;
}
示例8: whalemating_init
void whalemating_init() {
hold=lock_create("My lock");
male_sem=sem_create("Male Semaphore",0);
female_sem=sem_create("Female Semaphore",0);
mate_cv=cv_create("mating cv");
male_count=0;
female_count=0;
return;
}
示例9: config_con
int
config_con(struct con_softc *cs, int unit)
{
struct semaphore *rsem, *wsem;
struct lock *rlk, *wlk;
/*
* Only allow one system console.
* Further devices that could be the system console are ignored.
*
* Do not hardwire the console to be "con1" instead of "con0",
* or these asserts will go off.
*/
if (unit>0) {
KASSERT(the_console!=NULL);
return ENODEV;
}
KASSERT(the_console==NULL);
rsem = sem_create("console read", 0);
if (rsem == NULL) {
return ENOMEM;
}
wsem = sem_create("console write", 1);
if (wsem == NULL) {
sem_destroy(rsem);
return ENOMEM;
}
rlk = lock_create("console-lock-read");
if (rlk == NULL) {
sem_destroy(rsem);
sem_destroy(wsem);
return ENOMEM;
}
wlk = lock_create("console-lock-write");
if (wlk == NULL) {
lock_destroy(rlk);
sem_destroy(rsem);
sem_destroy(wsem);
return ENOMEM;
}
cs->cs_rsem = rsem;
cs->cs_wsem = wsem;
cs->cs_gotchars_head = 0;
cs->cs_gotchars_tail = 0;
the_console = cs;
con_userlock_read = rlk;
con_userlock_write = wlk;
flush_delay_buf();
return attach_console_to_vfs(cs);
}
示例10: stoplight_init
void stoplight_init() {
for(int i=0; i<DIRECTIONS;i++)
{
if(quadSem[i]==NULL){
quadSem[i] = sem_create("Quadrant Semaphore",1);
if (quadSem[i] == NULL) {
panic("synchtest: sem_create failed at quadSem\n");
}
}
}
if(mutex==NULL){
mutex = sem_create("mutex Semaphore",1);
if (mutex == NULL) {
panic("synchtest: sem_create failed at quadSem\n");
}
}
j[0]=0;
j[1]=0;
j[2]=0;
j[3]=0;
head[0]=1;
head[1]=1;
head[2]=1;
head[3]=1;
jlock=lock_create("j1lock");
/*jl[1]=lock_create("j2lock");
jl[2]=lock_create("j3lock");
jl[3]=lock_create("j4lock");
*/
/* if(quadSem1==NULL){
quadSem1 = sem_create("Quadrant 1 Semaphore",0);
if (quadSem1 == NULL) {
panic("synchtest: sem_create failed at quadSem1\n");
}
}
if(quadSem2==NULL){
quadSem2 = sem_create("Quadrant 2 Semaphore",0);
if (quadSem2 == NULL) {
panic("synchtest: sem_create failed at quadSem2\n");
}
}
if(quadSem3==NULL){
quadSem3 = sem_create("Quadrant 3 Semaphore",0);
if (quadSem3 == NULL) {
panic("synchtest: sem_create failed at quadSem3\n");
}
}
*/
return;
}
示例11: malloc
qsem_t *qsem_create (int count)
{
qsem_t *s;
s = (qsem_t *) malloc (sizeof (qsem_t));
#ifdef I386
s->mutex = sem_create (count, "qsem_mutex");
s->count = 0;
#else
s->mutex = sem_create (0, "qsem_mutex");
s->count = count;
#endif
return s;
}
示例12: test161_bootstrap
void test161_bootstrap()
{
test161_sem = sem_create("test161", 1);
if (test161_sem == NULL) {
panic("Failed to create test161 secprintf semaphore");
}
}
示例13: kmallocstress
int
kmallocstress(int nargs, char **args)
{
struct semaphore *sem;
int i, result;
(void)nargs;
(void)args;
sem = sem_create("kmallocstress", 0);
if (sem == NULL) {
panic("kmallocstress: sem_create failed\n");
}
kprintf("Starting kmalloc stress test...\n");
for (i=0; i<NTHREADS; i++) {
result = thread_fork("kmallocstress", NULL,
kmallocthread, sem, i);
if (result) {
panic("kmallocstress: thread_fork failed: %s\n",
strerror(result));
}
}
for (i=0; i<NTHREADS; i++) {
P(sem);
}
sem_destroy(sem);
kprintf("\n");
success(TEST161_SUCCESS, SECRET, "km2");
return 0;
}
示例14: initiateMating
static
void
initiateMating()
{
if (mateLock==NULL) {
mateLock = lock_create("mateLock");
if (mateLock == NULL) {
panic("mateLock: lock_create failed\n");
}
}
if (male_go==NULL) {
male_go = cv_create("male_go");
if (male_go == NULL) {
panic("male_go: cv_create failed\n");
}
}
if (female_go==NULL) {
female_go = cv_create("female_go");
if (female_go == NULL) {
panic("female_go: cv_create failed\n");
}
}
if (matchmaker_go==NULL) {
matchmaker_go = cv_create("matchmaker_go");
if (matchmaker_go == NULL) {
panic("matchmaker_go: cv_create failed\n");
}
}
if (doneSem==NULL) {
doneSem = sem_create("doneSem", 0);
if (doneSem == NULL) {
panic("doneSem: sem_create failed\n");
}
}
}
示例15: ves_icall_System_Threading_Semaphore_CreateSemaphore_internal
gpointer
ves_icall_System_Threading_Semaphore_CreateSemaphore_internal (gint32 initialCount, gint32 maximumCount, MonoString *name, gint32 *error)
{
gpointer sem;
if (maximumCount <= 0) {
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: maximumCount <= 0", __func__);
*error = ERROR_INVALID_PARAMETER;
return NULL;
}
if (initialCount > maximumCount || initialCount < 0) {
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: initialCount > maximumCount or < 0", __func__);
*error = ERROR_INVALID_PARAMETER;
return NULL;
}
/* Need to blow away any old errors here, because code tests
* for ERROR_ALREADY_EXISTS on success (!) to see if a
* semaphore was freshly created
*/
SetLastError (ERROR_SUCCESS);
if (!name)
sem = sem_create (initialCount, maximumCount);
else
sem = namedsem_create (initialCount, maximumCount, mono_string_chars (name));
*error = GetLastError ();
return sem;
}