本文整理汇总了C++中sem_create函数的典型用法代码示例。如果您正苦于以下问题:C++ sem_create函数的具体用法?C++ sem_create怎么用?C++ sem_create使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sem_create函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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) ;
}
开发者ID:bmeneguele,项目名称:sist-op,代码行数:28,代码来源:pingpong-semaphore.c
示例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");
}
}
}
开发者ID:patricksu,项目名称:repo3,代码行数:35,代码来源:bathroom_1Lock2CV_Final.c
示例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;
}
开发者ID:ChunHungLiu,项目名称:pikachuos,代码行数:28,代码来源:elves.c
示例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);
}
开发者ID:ChunHungLiu,项目名称:pikachuos,代码行数:36,代码来源:lhd.c
示例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");
}
}
}
开发者ID:DianeRay,项目名称:os161,代码行数:29,代码来源:synchtest.c
示例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);
}
开发者ID:aanrv,项目名称:Operating-Systems-Labs,代码行数:8,代码来源:solution.c
示例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;
}
开发者ID:HTshandou,项目名称:newos,代码行数:57,代码来源:pipefs.c
示例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;
}
开发者ID:nmanivas,项目名称:OS161,代码行数:9,代码来源:problems.c
示例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);
}
开发者ID:ChunHungLiu,项目名称:pikachuos,代码行数:55,代码来源:console.c
示例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;
}
开发者ID:karthik-j,项目名称:Operating-System-OS161-CS521-Spring-2015,代码行数:53,代码来源:problems.c
示例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;
}
开发者ID:danilaslau,项目名称:frotznet,代码行数:14,代码来源:qsem.c
示例12: test161_bootstrap
void test161_bootstrap()
{
test161_sem = sem_create("test161", 1);
if (test161_sem == NULL) {
panic("Failed to create test161 secprintf semaphore");
}
}
开发者ID:SidhantDuggal,项目名称:os161hack,代码行数:7,代码来源:test161.c
示例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;
}
开发者ID:riaz,项目名称:os161,代码行数:35,代码来源:kmalloctest.c
示例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");
}
}
}
开发者ID:patricksu,项目名称:repo3,代码行数:35,代码来源:whalemating_1Lock3CV_Final.c
示例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;
}
开发者ID:migueldeicaza,项目名称:mono,代码行数:34,代码来源:w32semaphore-unix.c
示例16: rwlock_create
struct rwlock * rwlock_create(const char *name){
struct rwlock *myrwlock;
myrwlock=kmalloc(sizeof(struct rwlock));
if(myrwlock==NULL){
return NULL;
}
myrwlock->rwlock_name = kstrdup(name);
if(myrwlock->rwlock_name==NULL){
kfree(myrwlock);
return NULL;
}
myrwlock->lk_read=lock_create("read");
myrwlock->lk_write=lock_create("write");
myrwlock->max_readers=30;
myrwlock->sem_resource=sem_create("resource",myrwlock->max_readers);
if(myrwlock->sem_resource==NULL){
kfree(myrwlock);
return NULL;
}
return myrwlock;
}
开发者ID:Pratik-Rajendra-Kolhe,项目名称:MS-Projects,代码行数:30,代码来源:synch.c
示例17: pipe_lock
// pub pipe lock
void pipe_lock()
{
if (sem_pipe < 0) {
if ( (sem_pipe = sem_create(SEMKEY_PIPE, 1)) < 0) err_sys("sem_create error for pipe lock");
}
sem_wait(sem_pipe);
}
开发者ID:lctseng,项目名称:104-1-NP_Graduated-Hw2,代码行数:8,代码来源:lock.hpp
示例18: snd_init
/* Initialize driver; note that this replaces the AICA program so that
if you had anything else going on, it's gone now! */
int snd_init() {
int amt;
/* Finish loading the stream driver */
if (!initted) {
spu_disable();
spu_memset(0, 0, AICA_RAM_START);
amt = snd_stream_drv_end - snd_stream_drv;
if (amt % 4)
amt = (amt + 4) & ~3;
printf("snd_init(): loading %d bytes into SPU RAM\n", amt);
spu_memload(0, snd_stream_drv, amt);
/* Enable the AICA and give it a few ms to start up */
spu_enable();
timer_spin_sleep(10);
/* Initialize the RAM allocator */
snd_mem_init(AICA_RAM_START);
/* Setup semaphores */
sem_qram = sem_create(1);
}
initted = 1;
return 0;
}
开发者ID:losinggeneration,项目名称:kos,代码行数:30,代码来源:snd_iface.c
示例19: rwlock_create
struct rwlock *
rwlock_create(const char *name)
{
struct rwlock *rw;
rw = kmalloc(sizeof(rw));
if(rw==NULL){
return NULL;
}
rw->rwlock_name=kstrdup(name);
if(rw->rwlock_name==NULL){
kfree(rw);
return NULL;
}
//Create Semaphore
rw->rwlock_semaphore = sem_create(rw->rwlock_name,MAX_READ);
if (rw->rwlock_semaphore == NULL) {
kfree(rw->rwlock_name);
kfree(rw);
return NULL;
}
//rw->read_count=0;
//Create Lock
rw->rwlock_lock=lock_create(rw->rwlock_name);
if (rw->rwlock_lock == NULL) {
kfree(rw->rwlock_name);
kfree(rw);
return NULL;
}
return rw;
}
开发者ID:coderpm,项目名称:OS161,代码行数:35,代码来源:synch.c
示例20: main
int main(void)
{
int freie_ressourcen;
/* Anlegen des Semaphors */
sem_anfordid = sem_create(SEM_READKEY);
/* Setzen des Sempahors auf 1 */
sem_set(sem_anfordid, 1);
/* Beginn Serverschleife */
while(1) {
/* Abfragen wieviel Ressourcen frei sind, falls 0 Schleife verlassen */
freie_ressourcen = sem_get(sem_anfordid);
if (freie_ressourcen == 0)
break;
/* eine Sekunde warten */
sleep(1);
/* Ende Serverschleife */
}
/* Semaphor entfernen */
sem_rm(sem_anfordid);
printf("Server terminiert.\n");
exit(0);
}
开发者ID:evamueller,项目名称:RuB2,代码行数:32,代码来源:sem_server.c
注:本文中的sem_create函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论