本文整理汇总了C++中sem_signal函数的典型用法代码示例。如果您正苦于以下问题:C++ sem_signal函数的具体用法?C++ sem_signal怎么用?C++ sem_signal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sem_signal函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: main
void main (int argc, char *argv[])
{
sem_t s_procs_completed; // Semaphore to signal the process that we're done
sem_t s_N2; //Semaphore as N2
int num_N2; //Number of N2
int i; //index var
if (argc != 4) {
Printf("Usage: "); Printf(argv[0]); Printf(" <handle_to_pass_complete_signal><s_procs_completed_str> <s_N2_str> <num_N2_str>\n");
Exit();
}
// Convert the command-line strings into integers for use as handles
s_procs_completed = dstrtol(argv[1], NULL, 10);
s_N2 = dstrtol(argv[2],NULL,10);
num_N2 =dstrtol(argv[3],NULL,10);
for(i=0;i<num_N2;i++){
Printf("Inject a N2\n");
sem_signal(s_N2);
}
// Signal the semaphore to tell the original process that we're done
// Printf("injection_n2 completed!\n");
if(sem_signal(s_procs_completed) != SYNC_SUCCESS) {
Printf("Bad semaphore s_procs_completed (%d) in ", s_procs_completed); Printf(argv[0]); Printf(", exiting...\n");
Exit();
}
}
开发者ID:Nelson0409,项目名称:DLX-OS,代码行数:27,代码来源:injection_n2.c
示例2: client
client()
{
int i;
/*
* Tell the server we're here and ready,
* then just receive while the server sends us things.
*/
sem_wait(clisem); /* get control of shared memory */
mesgptr->mesg_len = MESGLEN;
mesgptr->mesg_type = MESGLEN;
sem_signal(servsem); /* wake up server */
for (i = 0; i < NUMMESG; i++) {
sem_wait(clisem); /* wait for server */
if (mesgptr->mesg_len != MESGLEN)
err_sys("client: incorrect length");
if (mesgptr->mesg_type != (i + 1))
err_sys("client: incorrect type");
sem_signal(servsem); /* wake up server */
}
}
开发者ID:rkks,项目名称:refer,代码行数:25,代码来源:tim_shmcli.c
示例3: main
void main (int argc, char *argv[])
{
sem_t s_procs_completed; // Semaphore to signal the process that we're done
sem_t s_N; //Semaphore N
sem_t s_O2; //Semaphore O2
sem_t s_NO2; //Semaphore NO2
int num_N_O2_NO2; //number of reaction
int i; //index var
if (argc != 6) {
Printf("Usage: "); Printf(argv[0]); Printf(" <handle_to_signal_complete><s_H2O> <s_H2> <s_O2> <num_H2O_H2_O2> \n");
Exit();
}
// Convert the command-line strings into integers for use as handles
s_procs_completed = dstrtol(argv[1], NULL, 10);
s_N =dstrtol(argv[2],NULL,10);
s_O2 =dstrtol(argv[3],NULL,10);
s_NO2 =dstrtol(argv[4],NULL,10);
num_N_O2_NO2 = dstrtol(argv[5],NULL,10);
for(i=0;i<num_N_O2_NO2;i++){
sem_wait(s_N);
sem_wait(s_O2);
Printf("Create a NO2\n");
sem_signal(s_NO2);
}
// Printf("reaction3 completed\n");
if(sem_signal(s_procs_completed) != SYNC_SUCCESS) {
Printf("Bad semaphore s_procs_completed (%d) in ", s_procs_completed); Printf(argv[0]); Printf(", exiting...\n");
Exit();
}
}
开发者ID:Nelson0409,项目名称:DLX-OS,代码行数:34,代码来源:reaction3.c
示例4: canarrive
void canarrive(void* daddy) {
sem_acquire(&lock);
numcan++;
if(numcan == 3 || (numcan > 0 && nummiss == 2)){
sem_signal(&can);
sem_signal(&can);
printf(1, "\nRow Boat");
if (nummiss == 3){
printf(1, " with 3 missionaries");
nummiss = 0;
}
else if(numcan == 3){
printf(1, " with 3 cannibals");
numcan = 0;
}
else{
printf(1, " with 1 cannibal 2 missionaries");
numcan = numcan - 1;
nummiss = nummiss -2;
}
}
sem_signal(&lock);
texit();
}
开发者ID:kchan049,项目名称:xv6_sema_null,代码行数:25,代码来源:river.c
示例5: dominant_monkey_climb
void dominant_monkey_climb()
{
sem_acquire(&tree);
printf(1,"dominant Monkey %d gets coconut\n", getpid());
sem_signal(&tree);
sem_signal(&dominant_monkey);
texit();
}
开发者ID:jthak002,项目名称:CS153-Spring2016,代码行数:8,代码来源:synch2.c
示例6: snd_aica_to_sh4
/* Transfer one packet of data from the AICA->SH4 queue. Expects to
find AICA_CMD_MAX_SIZE dwords of space available. Returns -1
if failure, 0 for no packets available, 1 otherwise. Failure
might mean a permanent failure since the queue is probably out of sync. */
int snd_aica_to_sh4(void *packetout) {
uint32 bot, start, stop, top, size, cnt, *pkt32;
sem_wait(sem_qram);
/* Set these up for reference */
bot = SPU_RAM_BASE + AICA_MEM_RESP_QUEUE;
assert_msg( g2_read_32(bot + offsetof(aica_queue_t, valid)), "Queue is not yet valid" );
top = SPU_RAM_BASE + AICA_MEM_RESP_QUEUE + g2_read_32(bot + offsetof(aica_queue_t, size));
start = SPU_RAM_BASE + AICA_MEM_RESP_QUEUE + g2_read_32(bot + offsetof(aica_queue_t, tail));
stop = SPU_RAM_BASE + AICA_MEM_RESP_QUEUE + g2_read_32(bot + offsetof(aica_queue_t, head));
cnt = 0;
pkt32 = (uint32 *)packetout;
/* Is there anything? */
if (start == stop) {
sem_signal(sem_qram);
return 0;
}
/* Check for packet size overflow */
size = g2_read_32(start + offsetof(aica_cmd_t, size));
if (cnt >= AICA_CMD_MAX_SIZE) {
sem_signal(sem_qram);
dbglog(DBG_ERROR, "snd_aica_to_sh4(): packet larger than %d dwords\n", AICA_CMD_MAX_SIZE);
return -1;
}
/* Find stop point for this packet */
stop = start + size*4;
if (stop > top)
stop -= top - (SPU_RAM_BASE + AICA_MEM_RESP_QUEUE);
while (start != stop) {
/* Fifo wait if necessary */
if (!(cnt % 8))
g2_fifo_wait();
cnt++;
/* Read the next dword */
*pkt32++ = g2_read_32(start);
/* Move our counters */
start += 4;
if (start >= top)
start = bot;
cnt++;
}
/* Finally, write a new tail value to signify that we've removed a packet */
g2_write_32(bot + offsetof(aica_queue_t, tail), start - (SPU_RAM_BASE + AICA_MEM_RESP_QUEUE));
sem_signal(sem_qram);
return 1;
}
开发者ID:losinggeneration,项目名称:kos,代码行数:61,代码来源:snd_iface.c
示例7: barber
void barber() {
while(true) {
sem_wait(customer_waiting);
sem_wait(seats_mutex);
free_seats++;
cut_hair();
sem_signal(barber_sleeping);
sem_signal(seats_mutex);
}
}
开发者ID:jayrbolton,项目名称:coursework,代码行数:10,代码来源:barber.c
示例8: oReady
void oReady(void *arg_ptr) {
sem_acquire(&h);
sem_acquire(&h);
sem_signal(&o);
sem_signal(&o);
lock_acquire(&mutex);
water_molecules++;
lock_release(&mutex);
texit();
}
开发者ID:aesgu001,项目名称:xv6-lab2,代码行数:10,代码来源:t_sema1_random.c
示例9: append_fat
BOOL append_fat (VOL_PTR tab , const dword chain, dword * addr) {
fat_ptr fat=NULL;
dword cluster_ultimo=0, cluster_new=0;
if(!(tab)) {
set_errno(EINVAL,"Volume errato (%s-line%d)", __FILE__, __LINE__);
return FALSE;
}
if(chain <2 ) {
set_errno(EINVAL,"Cluster riservato");
return FALSE;
}
fat=tab->fat;
sem_wait(tab->sem_fat);
if(!get_ultimo_fat(fat, chain, &cluster_ultimo)) {
sem_signal(tab->sem_fat);
return FALSE;
}
if(!getFree_fat(fat, tab->size_fat,&cluster_new)) {
sem_signal(tab->sem_fat);
return FALSE;
}
//devo scrivere nell'ultimo l'indirizzo del nuovo cluster
if(!scrivi_fat(tab, cluster_ultimo, cluster_new)) {
sem_signal(tab->sem_fat);
return FALSE;
}
if(!scrivi_fat(tab, cluster_new, EOC_32)) {
// se fallisce provo a ripristinare la situazione precedente
if(!scrivi_fat(tab, cluster_ultimo, EOC_32))
set_errno(EIO,"Errore irrecuperabile, possibile perdita di dati");
sem_signal(tab->sem_fat);
return FALSE;
}
// ... ----->Ultimo---->new(EOC);
// finito inserimento
sem_signal(tab->sem_fat);
if(addr)
*addr=cluster_new;
return TRUE;
}
开发者ID:giuse88,项目名称:nucleo,代码行数:55,代码来源:fat.c
示例10: main
void main(int argc, char ** argv)
{
uint32 h_mem;
sem_t s_procs_completed;
Molecules * mols;
int ct;
if (argc != 3) {
Printf("Usage: ");
Printf(argv[0]);
Printf(" <handle_to_shared_memory_page> <handle_to_page_mapped_semaphore>\n");
Exit();
}
// Convert the command-line strings into integers for use as handles
h_mem = dstrtol(argv[1], NULL, 10); // The "10" means base 10
s_procs_completed = dstrtol(argv[2], NULL, 10);
// Map shared memory page into this process's memory space
if ((mols = (Molecules *) shmat(h_mem)) == NULL) {
Printf("Could not map the shared page to virtual address in ");
Printf(argv[0]);
Printf(", exiting..\n");
Exit();
}
for(ct = 0; ct < mols->init_so4; ct++) {
// Consume SO4
sem_wait(mols->so4);
// Produce so2
sem_signal(mols->so2);
Printf("A molecule SO2 is created\n");
// Produce O2
sem_signal(mols->o2);
Printf("A molecule O2 is created\n");
}
// Signal the semaphore to tell the original process that we're done
Printf("Reaction 2: PID %d is complete.\n", getpid());
if(sem_signal(s_procs_completed) != SYNC_SUCCESS) {
Printf("Bad semaphore s_procs_completed (%d) in ", s_procs_completed);
Printf(argv[0]);
Printf(", exiting...\n");
Exit();
}
return;
}
开发者ID:zhan1182,项目名称:OS-Design,代码行数:54,代码来源:reaction_2.c
示例11: CannibalArrives
void CannibalArrives()
{
sem_aquire(&boat);
sem_aquire(&display);
printf(1, "1: (%d) cannibal arrived, %d, %d\n", getpid(), total, con);
sem_signal(&display);
sem_aquire(&mutex2);
while(total + 2 == 5) { con++;
sem_signal(&mutex2);
sem_signal(&boat);
sem_aquire(&display);
printf(1, "1: (%d) cannibal denied boarding, %d, %d\n", getpid(), total, con);
sem_signal(&display);
sem_aquire(&prevention);
sem_aquire(&display);
printf(1, "1: (%d) cannibal prevented meal, %d, %d\n", getpid(), total, con);
sem_signal(&display);
sem_aquire(&boat);
sem_aquire(&mutex2);
}
sem_signal(&mutex2);
sem_aquire(&mutex2);
total += 2;
sem_signal(&mutex2);
sem_aquire(&display);
printf(1, "2: (%d) cannibal enters boat, %d, %d\n", getpid(), total, con);
sem_signal(&display);
sem_aquire(&mutex);
bp++;
sem_signal(&mutex);
if (bp < 3) sem_aquire(&loading);
// sem_aquire(&display);
// printf(1, "bp cannibal: %d\n", bp);
// sem_signal(&display);
RowBoat();
sem_signal(&loading);
texit();
}
开发者ID:fyang016,项目名称:CS153-Spring-2016,代码行数:54,代码来源:boat.c
示例12: cb_default
static void cb_default(const char *str) {
cb_sem_data_t *t;
t = malloc(sizeof(cb_sem_data_t));
sem_wait(cb_mutex);
strncpy(t->line, str, 255); t->line[255] = '\0';
t->next = (cb_sem_data_t *)cb_queue;
cb_queue = t;
sem_signal(cb_mutex);
sem_signal(cb_sem);
}
开发者ID:foreverlikeyou9999,项目名称:kos-ports,代码行数:12,代码来源:input.c
示例13: oReady
void oReady(void* v)
{
sem_acquire(&h);
sem_acquire(&h);
sem_signal(&o);
sem_signal(&o);
sem_acquire(&l);
water++;
printf(1,"water molecule created\n");
sem_signal(&l);
texit();
}
开发者ID:athai005,项目名称:xv6_lab2,代码行数:13,代码来源:h2o.c
示例14: MissionaryArrives
void MissionaryArrives()
{
sem_aquire(&boat);
sem_aquire(&display);
printf(1, "1: (%d) missionary arrived, %d, %d\n", getpid(), total, con);
sem_signal(&display);
sem_aquire(&mutex2);
while(total + 1 == 5){ con++;
sem_signal(&mutex2);
sem_signal(&boat);
sem_aquire(&display);
printf(1, "1: (%d) missionary denied boarding, %d, %d\n", getpid(), total, con);
sem_signal(&display);
sem_aquire(&prevention);
sem_aquire(&display);
printf(1, "1: (%d) missionary prevented death, %d, %d\n", getpid(), total, con);
sem_signal(&display);
sem_aquire(&boat);
sem_aquire(&mutex2);
}
sem_signal(&mutex2);
sem_aquire(&mutex2);
total += 1;
sem_signal(&mutex2);
sem_aquire(&display);
printf(1, "2: (%d) missionary enters boat, %d, %d\n", getpid(), total, con);
sem_signal(&display);
sem_aquire(&mutex);
bp++;
sem_signal(&mutex);
if (bp < 3) sem_aquire(&loading);
// sem_aquire(&display);
// printf(1, "bp missionary: %d\n", bp);
// sem_signal(&display);
RowBoat();
sem_signal(&loading);
texit();
}
开发者ID:fyang016,项目名称:CS153-Spring-2016,代码行数:51,代码来源:boat.c
示例15: customer
void customer() {
sem_wait(seats_mutex);
if(free_seats > 0) {
free_seats--;
sem_signal(customer_waiting);
sem_signal(seats_mutex);
sem_wait(barber_sleeping);
get_haircut();
}
else {
sem_signal(seats_mutex);
leave();
}
}
开发者ID:jayrbolton,项目名称:coursework,代码行数:14,代码来源:barber.c
示例16: delete_fat
BOOL delete_fat (VOL_PTR tab, const dword chain) {
fat_ptr fat=NULL;
dword cluster_ultimo=0,cluster_penultimo=0;
dword backup=0;
if(!(tab)) {
set_errno(EINVAL,"Volume errato (%s-line%d)", __FILE__, __LINE__);
return FALSE;
}
if(chain < 2) {
set_errno(1,"Cluster riservati");
return FALSE;
}
fat=tab->fat;
leggi_fat(fat,cluster_penultimo,&backup);
sem_wait(tab->sem_fat);
if(!get_ultimo_fat(fat, chain, &cluster_ultimo)) {
sem_signal(tab->sem_fat);
return FALSE;
}
if(!get_penUltimo_fat(fat, chain, &cluster_penultimo)) {
sem_signal(tab->sem_fat);
return FALSE;
}
if(!scrivi_fat(tab, cluster_penultimo, EOC_32))
return FALSE;
if(!scrivi_fat(tab, cluster_ultimo, FREE_32)) {
if(!scrivi_fat(tab, cluster_penultimo, backup))
set_errno(1,"Errore irrecuperabile, possibile perdita di dati");
sem_signal(tab->sem_fat);
return FALSE;
}
sem_signal(tab->sem_fat);
return TRUE;
}
开发者ID:giuse88,项目名称:nucleo,代码行数:50,代码来源:fat.c
示例17: main
void main(int argc, char * argv[])
{
//Local Variables
int num = 0, i, j;
sem_t sem_sulphate, sem_sulphur, sem_oxygen, proc_sem;
if(argc != 6)
{
Printf("Usage: "); Printf(argv[0]);
Exit();
}
num = dstrtol(argv[1], NULL, 10);
sem_sulphate = dstrtol(argv[2], NULL, 10);
sem_sulphur = dstrtol(argv[3], NULL, 10);
sem_oxygen = dstrtol(argv[4], NULL, 10);
proc_sem = dstrtol(argv[5], NULL, 10);
for(i = 0; i < num; i++)
{
if (sem_wait(sem_sulphate) != SYNC_SUCCESS) {
Printf("Bad semaphore of sulphate sem wait (%d) in reaction 2", sem_sulphate); Printf(argv[0]); Printf("\n");
Exit();
}
for(j = 0; j < SO2_NUM; j++)
{
if((sem_signal(sem_sulphur))!= SYNC_SUCCESS) {
Printf("Bad semaphore for SO2 increment in reaction 2 : (%d) ", getpid()); Printf(argv[0]); Printf(", exiting...\n");
Exit();
}
Printf("Created new sulphur dioxide (S02) molecule\n");
}
for(j = 0; j < O_NUM; j++)
{
if(sem_signal(sem_oxygen) != SYNC_SUCCESS) {
Printf("Bad semaphore for O increment in reaction 2 : (%d) ", getpid()); Printf(argv[0]); Printf(", exiting...\n");
Exit();
}
Printf("Created new oxygen (O2) molecule\n");
}
}
if(sem_signal(proc_sem) != SYNC_SUCCESS) {
Printf("Bad semaphore for proc sem increment in reaction : %d ", getpid()); Printf(argv[0]); Printf(", exiting...\n");
Exit();
}
}
开发者ID:aggarw13,项目名称:ECE469_Operating_Systems,代码行数:49,代码来源:reaction2.c
示例18: main
void main(int argc, char * argv[])
{
//Local Variables
int num = 0, i, j;
sem_t sem_sulphur, sem_oxygen, sem_hydrogen, sem_acid, proc_sem;
if(argc != 7)
{
Printf("Usage: "); Printf(argv[0]);
Exit();
}
num = dstrtol(argv[1], NULL, 10);
sem_hydrogen = dstrtol(argv[2], NULL, 10);
sem_oxygen = dstrtol(argv[3], NULL, 10);
sem_sulphur = dstrtol(argv[4], NULL, 10);
sem_acid = dstrtol(argv[5], NULL, 10);
proc_sem = dstrtol(argv[6], NULL, 10);
for(i = 0; i < num; i++)
{
if (sem_wait(sem_hydrogen) != SYNC_SUCCESS) {
Printf("Bad semaphore of hydrogen sem wait (%d) in reaction 3", sem_hydrogen); Printf(argv[0]); Printf("\n");
Exit();
}
if (sem_wait(sem_oxygen) != SYNC_SUCCESS) {
Printf("Bad semaphore of oxygen sem wait (%d) in reaction 3", sem_oxygen); Printf(argv[0]); Printf("\n");
Exit();
}
if (sem_wait(sem_sulphur) != SYNC_SUCCESS) {
Printf("Bad semaphore of sulphate sem wait (%d) in reaction 3", sem_sulphur); Printf(argv[0]); Printf("\n");
Exit();
}
if(sem_signal(sem_acid) != SYNC_SUCCESS) {
Printf("Bad semaphore for SO2 increment in reaction 3 : (%d) ", getpid()); Printf(argv[0]); Printf(", exiting...\n");
Exit();
}
Printf("Created new sulphuric acid (H2S04) molecule\n");
}
if(sem_signal(proc_sem) != SYNC_SUCCESS) {
Printf("Bad semaphore for proc sem increment in reaction 3 : %d ", getpid()); Printf(argv[0]); Printf(", exiting...\n");
Exit();
}
}
开发者ID:aggarw13,项目名称:ECE469_Operating_Systems,代码行数:49,代码来源:reaction3.c
示例19: el_loader_init
int el_loader_init(void)
{
PRINTF("entrylist_load_init...\n");
spinlock_init(&loader_mutex);
memset(&loader, 0, sizeof(loader));
loader_status = LOADER_INIT;
loader_thd = 0;
PRINTF("entrylist_load_init : create semaphore.\n");
loader_sem = sem_create(1);
PRINTF("entrylist_load_init : semaphore [%p].\n",loader_sem);
if (!loader_sem) {
printf("entrylist_load_init : can not create semaphore.\n");
return -1;
}
PRINTF("entrylist_load_init : first wait semaphore.\n");
sem_wait(loader_sem);
PRINTF("entrylist_load_init : create thread.\n");
loader_thd = thd_create(THD_DEFAULTS, loader_thread, loader_sem);
if (!loader_thd) {
printf("entrylist_load_init : thread failed.\n");
sem_signal(loader_sem);
sem_destroy(loader_sem);
loader_sem = 0;
printf("entrylist_load_init : can not create loader thread.\n");
return -1;
}
PRINTF("entrylist_load_init : thread created, rename it.\n");
thd_set_label((kthread_t *)loader_thd, "Loader-thd");
PRINTF("entrylist_load_init : complete (thd=%p).\n", loader_thd);
return 0;
}
开发者ID:pcercuei,项目名称:dcplaya,代码行数:33,代码来源:entrylist_loader.c
示例20: main
void main (int argc, char *argv[])
{
sem_t s_procs_completed; // Semaphore to signal the original process that we're done
int N = 10000;
int f_N;
if (argc != 2) {
Printf("Usage: %s <handle_to_procs_completed_semaphore>\n");
Exit();
}
// Convert the command-line strings into integers for use as handles
s_procs_completed = dstrtol(argv[1], NULL, 10);
f_N = f(N);
Printf("f %d = %d\n", N, f_N);
// Signal the semaphore to tell the original process that we're done
if(sem_signal(s_procs_completed) != SYNC_SUCCESS) {
Printf("hello_world (%d): Bad semaphore s_procs_completed (%d)!\n", getpid(), s_procs_completed);
Exit();
}
Printf("q2.3 cause the call stack to grow larger than 1 page (%d): Done!\n", getpid());
}
开发者ID:zhan1182,项目名称:OS-Design,代码行数:30,代码来源:q2_3.c
注:本文中的sem_signal函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论