本文整理汇总了C++中sema_up函数的典型用法代码示例。如果您正苦于以下问题:C++ sema_up函数的具体用法?C++ sema_up怎么用?C++ sema_up使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sema_up函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: agent_fun
void agent_fun(void *aux){
int i=0;
while(i<5){
sema_down(&agent);
long num=random_ulong()%3;
if (tobaco_match==num)
{
sema_up(&smoker1);
}else if(match_paper==num){
sema_up(&smoker2);
}else if(paper_tobaco){
sema_up(&smoker3);
}
i++;
}
}
开发者ID:vkc932,项目名称:pintos,代码行数:25,代码来源:5cs44_backup.c
示例2: do_grad
void do_grad(int* studentsInRoom, sema gradAllowedMutex, int* gradsEaten, sema roomTypeMutex, enum studentType* currentStudentType) {
while (1) {
sema_down(gradAllowedMutex);
sema_down(roomTypeMutex);
if (*currentStudentType != ugrad && *studentsInRoom < 2) {
(*studentsInRoom) += 1;
*currentStudentType = grad;
sema_up(roomTypeMutex);
(*gradsEaten) += 1;
// 6 grads have eaten, lock out more grads until ugrads get a turn
if (*gradsEaten == NUM_GRADS) { sema_down(gradAllowedMutex); }
printf("grad eating...\n");
sleep(randint());
printf(" grad done\n");
sema_down(roomTypeMutex);
(*studentsInRoom) -= 1;
if (*studentsInRoom == 0) { *currentStudentType = empty; }
sema_up(roomTypeMutex);
} else {
sema_up(roomTypeMutex);
}
}
}
开发者ID:Petesta,项目名称:cs170-synchronization,代码行数:27,代码来源:pizza.c
示例3: ArriveBridge
void ArriveBridge(int direc,int prio)
{
sema_down(&mutex);
if(prio == 1)total_urgent_waiting++;
while(true)
{
if((bridge_direction == direc || bridge.value == 3) && (total_urgent_waiting == 0 || prio == 1))
{
sema_down(&bridge);
bridge_direction = direc;
if(prio == 1)total_urgent_waiting--;
//sema_down(&inform);
printf("%s %d %s %d\n","MOVING ON Origin =",direc,"Priority =",prio);
//sema_up(&inform);
sema_up(&mutex);
break;
}
else
{
//sema_down(&inform);
printf("%s %d %s %d\n","CAN NOT PROCEED Origin =",direc,"Priority =",prio);
//sema_up(&inform);
}
sema_up(&mutex);
thread_yield();
sema_down(&mutex);
}
}
开发者ID:2ral,项目名称:pintos,代码行数:28,代码来源:narrow-bridge.c
示例4: smoker1_fun
void smoker1_fun(void *aux){
while(1){
sema_down(&smoker1);
printf("I AM SMOKER 1\n");
sema_up(&agent);
}
}
开发者ID:vkc932,项目名称:pintos,代码行数:7,代码来源:5cs44_backup.c
示例5: sys_exit
void
sys_exit (int status)
{
struct thread *t = thread_current();
int fd;
t->exit_code = status;
t->end = true;
for (fd=0; fd < t->fd_num; fd++){ // close all open fd
if (t->fd_list[fd] != NULL){
file_close(t->fd_list[fd]);
t->fd_list[fd] = 0;
}
}
printf("%s: exit(%d)\n", t->process_name, status);
sema_up (&t->wait_this);
//unblock parent
sema_down (&t->kill_this);
//kill_this will up when parent get exit_code succefully
file_allow_write (t->open_file);
file_close (t->open_file);
thread_exit();
}
开发者ID:jsquaredlau,项目名称:PINTOS_PROJECT_3,代码行数:26,代码来源:syscall.c
示例6: test_priority_sema
void
test_priority_sema (void)
{
int i;
/* This test does not work with the MLFQS. */
ASSERT (!thread_mlfqs);
sema_init (&sema, 0);
thread_set_priority (PRI_MIN);
for (i = 0; i < 10; i++)
{
int priority = PRI_DEFAULT - (i + 3) % 10 - 1;
char name[16];
snprintf (name, sizeof name, "priority %d", priority);
thread_create (name, priority, priority_sema_thread, NULL);
}
for (i = 0; i < 10; i++)
{
sema_up (&sema);
msg ("Back in main thread.");
}
}
开发者ID:Roozbehy,项目名称:pintos,代码行数:27,代码来源:priority-sema.c
示例7: lock_release
/* Releases LOCK, which must be owned by the current thread.
An interrupt handler cannot acquire a lock, so it does not
make sense to try to release a lock within an interrupt
handler. */
void
lock_release (struct lock *lock)
{
ASSERT (lock != NULL);
ASSERT (lock_held_by_current_thread (lock));
enum intr_level old_state = intr_disable();
// Remove all donors that hold this lock
if (!list_empty(&thread_current()->donorList))
{
struct list_elem *e, *tmp;
for (e = list_begin(&thread_current()->donorList);
e != list_end(&thread_current()->donorList);
e = tmp)
{
struct thread *t = list_entry(e, struct thread, donorElem);
tmp = list_next(e);
if (t->tLock == lock) list_remove(e);
}
}
intr_set_level(old_state);
lock->holder = NULL;
sema_up (&lock->semaphore);
//intr_set_level(old_state);
}
开发者ID:cthan004,项目名称:pintos,代码行数:31,代码来源:synch.c
示例8: lock_release
/* Releases LOCK, which must be owned by the current thread.
An interrupt handler cannot acquire a lock, so it does not
make sense to try to release a lock within an interrupt
handler. */
void
lock_release (struct lock *lock)
{
ASSERT (lock != NULL);
ASSERT (lock_held_by_current_thread (lock));
enum intr_level old_level = intr_disable ();
lock->holder = NULL;
/* If we're using the priority scheduler, loop through all threads
that were waiting on this lock and notify them to remove their
priority donations. */
if (!thread_mlfqs)
{
struct list_elem *e;
for (e = list_begin (&lock->semaphore.waiters);
e != list_end (&lock->semaphore.waiters);
e = list_next (e))
{
struct thread *t = list_entry (e, struct thread, elem);
thread_recall_donation (t);
}
/* Recompute my effective priority, since I may have just lost
some donations. */
thread_calculate_priority (thread_current ());
}
lock->holder = NULL;
/* NOTE : It's possible that we will be preempted by sema_up. */
sema_up (&lock->semaphore);
intr_set_level (old_level);
}
开发者ID:CSthrowaway,项目名称:cs140-w2012-stevejosh,代码行数:38,代码来源:synch.c
示例9: lock_release
/* Releases LOCK, which must be owned by the current thread.
An interrupt handler cannot acquire a lock, so it does not
make sense to try to release a lock within an interrupt
handler. */
void
lock_release (struct lock *lock)
{
bool yield = false;
ASSERT (lock != NULL);
ASSERT (lock_held_by_current_thread (lock));
enum intr_level old_level = intr_disable ();
if (!thread_mlfqs &&
thread_current ()->is_a_donee)
{
thread_reverse_priority_donation (lock);
yield = true;
}
lock->holder = NULL;
sema_up (&lock->semaphore);
intr_set_level (old_level);
if (yield)
thread_yield ();
}
开发者ID:RichardH92,项目名称:Pintos_Project_1,代码行数:31,代码来源:synch.c
示例10: timer_sleep
/* Sleeps for approximately TICKS timer ticks. Interrupts must
be turned on. */
void
timer_sleep (int64_t ticks)
{
int64_t start = timer_ticks ();
ASSERT (intr_get_level () == INTR_ON);
enum intr_level old_level;
struct wait_sema current_thread;
sema_init (¤t_thread.sleep_sema,0);
sema_down (&sema_calc_tick);
current_thread.wakeup_tick = start+ticks;
sema_up (&sema_calc_tick);
old_level = intr_disable();
list_insert_ordered (&wait_sema_list,¤t_thread.elem,wakeup_order,NULL);
intr_set_level (old_level);
sema_down (¤t_thread.sleep_sema);
/*Old Code*/
// while (timer_elapsed (start) < ticks)
// thread_yield ();
}
开发者ID:mithunatri,项目名称:Pintos-OS-,代码行数:29,代码来源:timer.c
示例11: syscall_exit
void syscall_exit(int status){
/* Terminates the current user program, returning status to the kernel.
*
* If the process's parent waits for it, this is the status that
* will be returnd.
*
* Conventionally, a status of 0 indicates success and nonzero values
* indicate errors. (ref:man29-30)
*/
struct thread *t = thread_current ();
char *wanted, *last;
wanted = strtok_r(t->name, " ", &last);
printf("%s: exit(%d)\n", wanted, status);
// XXX : Delete All unremoved FPs.
struct list_elem *e;
for (e = list_begin(&(t->FDs));
e != list_end(&(t->FDs));
/* XXX inside. */){
struct fd_list *now = list_entry(e, struct fd_list, elem);
e = list_next(e);
// printf("%s(%d) NOW FD_list %d\n", __func__, __LINE__, now->fd);
close_fd_list(now);
}
// XXX : Delete Child from Parent.
struct thread *parent = t->parent;
// XXX : Wait until parent waiting child.
while(!( (t->parent->status == THREAD_BLOCKED)
&& (t->parent->waiting_tid == t->tid) )){
thread_yield();
}
// SEARCH It;
for (e = list_begin(&(parent->childs));
e != list_end(&(parent->childs));
/* */){
//printf("list anything out: %p\n", (void *)e);
struct child_list *now = list_entry(e,
struct child_list,
elem);
e = list_next(e);
if(now->tid == t->tid)
// Unlink Child from Parent;
if(&(now->elem)){
//free(list_remove(e));
list_remove(&(now->elem));
free(now);
break;
}
}
// XXX : Store return status to parent.
t->parent->waited_child_return_value = status;
// XXX : Wakeup Parent.
//printf("[%s/%s]SEMAUP? %d\n", t->parent->name, t->name, t->parent->sema.value);
sema_up(&(t->parent->sema));
//printf("[%s/%s]SEMAUP! %d\n", t->parent->name, t->name, t->parent->sema.value);
// XXX
thread_exit();
return ;
}
开发者ID:JaehyunAhn,项目名称:MinHo-JaeHyun-OperatingSystem-Pintos-Prj,代码行数:59,代码来源:syscall.c
示例12: syscall_exit
void syscall_exit(int value) {
struct exit_struct *ec = thread_current()->exit_controler;
printf("%s: exit(%d)\n", thread_name(), value);
ec->value = value;
sema_up(&ec->parent);
thread_exit();
}
开发者ID:coweatyou,项目名称:school,代码行数:8,代码来源:syscall.c
示例13: thread_cleanup_and_exit
void
thread_cleanup_and_exit (int status)
{
printf ("%s: exit(%d)\n", thread_name (), status);
/* close all open file descriptors */
struct thread *t = thread_current ();
struct list_elem *e;
/* close all the files opened and
free spaces allocated for the file list */
while (!list_empty (&t->file_list))
{
e = list_pop_back (&t->file_list);
struct file_elem *f_elem = list_entry (e, struct file_elem, elem);
file_close (f_elem->file);
free (f_elem);
}
/* free waited_children_list and children_list */
while (!list_empty (&t->children_list))
{
e = list_pop_back (&t->children_list);
struct child_elem *c_elem = list_entry (e, struct child_elem, elem);
// free children from the global exit_list
free_thread_from_exit_list (c_elem->pid);
free (c_elem);
}
while (!list_empty (&t->waited_children_list))
{
e = list_pop_back (&t->waited_children_list);
struct wait_child_elem *w_elem = list_entry (e, struct wait_child_elem, elem);
free (w_elem);
}
add_thread_to_exited_list (t->tid, status);
/* allow file write to executable */
if (t->exec_file)
{
file_allow_write (t->exec_file);
file_close (t->exec_file);
}
/* release all the locks that have not already been released */
while (!list_empty (&t->acquired_locks))
{
struct list_elem *e = list_front (&t->acquired_locks);
struct lock *l = list_entry (e, struct lock, elem);
lock_release (l);
}
/* wake parent up if its waiting on it */
struct thread *parent = get_thread (thread_current ()->parent_id);
if (parent) {
sema_up (&parent->waiting_on_child_exit_sema);
}
thread_exit ();
}
开发者ID:rahulabc,项目名称:jawpintos,代码行数:58,代码来源:syscall.c
示例14: sema_test_helper
/*! Thread function used by sema_self_test(). */
static void sema_test_helper(void *sema_) {
struct semaphore *sema = sema_;
int i;
for (i = 0; i < 10; i++) {
sema_down(&sema[0]);
sema_up(&sema[1]);
}
}
开发者ID:waffleOS,项目名称:waffle,代码行数:10,代码来源:synch.c
示例15: lock_release
/* Releases LOCK, which must be owned by the current thread.
An interrupt handler cannot acquire a lock, so it does not
make sense to try to release a lock within an interrupt
handler. */
void
lock_release (struct lock *lock)
{
ASSERT (lock != NULL);
ASSERT (lock_held_by_current_thread (lock));
lock->holder = NULL;
sema_up (&lock->semaphore);
}
开发者ID:atlus7,项目名称:pintos,代码行数:14,代码来源:synch.c
示例16: sysexit
void
sysexit(int status)
{
// Print Process Termination Message
// File Name
char* name = thread_current()->name;
char* token, *save_ptr;
token = strtok_r(name, " ", &save_ptr);
putbuf (token, strlen(token));
char* str1 = ": exit(";
putbuf (str1, strlen(str1));
// ExitStatus
char strstatus[32];
snprintf(strstatus, 32, "%d", status);
putbuf (strstatus, strlen(strstatus));
char* str2 = ")\n";
putbuf (str2, strlen(str2));
// EXIT Child Processes
if(thread_current()->numchild > 0)
{
struct list_elem * e;
while (!list_empty(&thread_current()->child_list))
{
e = list_pop_front(&thread_current()->child_list);
struct childproc * childitem = list_entry (e, struct childproc, elem);
if(!exit_remove(childitem->childid))
{
list_push_back(&ignore_list, &childitem->elem);
}
else
{
free(childitem);
}
}
}
// Save exit status
struct exitstatus * es = (struct exitstatus *) malloc(sizeof(struct exitstatus));
if(es != NULL && !ignore_remove(thread_current()->tid))
{
es->avail = true;
es->status = status;
es->childid = thread_current()->tid;
list_push_back(&exit_list, &es->elem);
struct list_elem * e;
for (e = list_begin (&waitproc_list); e != list_end (&waitproc_list); e = list_next (e))
{
struct waitproc * item = list_entry (e, struct waitproc, elem);
sema_up(&item->sema);
}
}
开发者ID:rdspring1,项目名称:Porsche911,代码行数:56,代码来源:syscall.c
示例17: lock_release
/*! Releases LOCK, which must be owned by the current thread.
An interrupt handler cannot acquire a lock, so it does not
make sense to try to release a lock within an interrupt
handler. */
void lock_release(struct lock *lock) {
ASSERT(lock != NULL);
ASSERT(lock_held_by_current_thread(lock));
lock->holder = NULL;
lock->donated_priority = PRI_MIN;
list_remove(&lock->elem);
sema_up(&lock->semaphore);
thread_yield();
}
开发者ID:waffleOS,项目名称:waffle,代码行数:15,代码来源:synch.c
示例18: lock_release
/* Releases LOCK, which must be owned by the current thread.
An interrupt handler cannot acquire a lock, so it does not
make sense to try to release a lock within an interrupt
handler. */
void
lock_release (struct lock *lock)
{
ASSERT (lock != NULL);
ASSERT (lock_held_by_current_thread (lock));
lock->holder = NULL;
sema_up (&lock->semaphore); /* May yield if the newly unblocked thread is of
higher priority than the current thread. */
}
开发者ID:Hindol,项目名称:pintos,代码行数:15,代码来源:synch.c
示例19: lock_release
/* Releases LOCK, which must be owned by the current thread.
An interrupt handler cannot acquire a lock, so it does not
make sense to try to release a lock within an interrupt
handler. */
void
lock_release (struct lock *lock)
{
ASSERT (lock != NULL);
ASSERT (lock_held_by_current_thread (lock));
list_remove(&(lock->hold_elem));
lock_recall_priority();
lock->holder = NULL;
sema_up (&lock->semaphore);
}
开发者ID:smssss,项目名称:pintos-project1,代码行数:16,代码来源:synch.c
示例20: lock_release
/* Releases LOCK, which must be owned by the current thread.
An interrupt handler cannot acquire a lock, so it does not
make sense to try to release a lock within an interrupt
handler. */
void
lock_release (struct lock *lock)
{
ASSERT (lock != NULL);
ASSERT (lock_held_by_current_thread (lock));
enum intr_level old_level = intr_disable ();
thread_remove_donations(lock->holder, lock);
lock->holder = NULL;
sema_up (&lock->semaphore);
intr_set_level (old_level);
}
开发者ID:raunk,项目名称:cs140,代码行数:17,代码来源:synch.c
注:本文中的sema_up函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论