134 printf (
"Testing semaphores...");
138 for (i = 0; i < 10; i++)
153 for (i = 0; i < 10; i++)
#define ASSERT(CONDITION)
This is outside the header guard so that debug.h may be included multiple times with different settin...
#define UNUSED
GCC lets us add "attributes" to functions, function parameters, etc.
bool intr_context(void)
Returns true during processing of an external interrupt and false at all other times.
enum intr_level intr_disable(void)
Disables interrupts and returns the previous interrupt status.
enum intr_level intr_set_level(enum intr_level level)
Enables or disables interrupts as specified by LEVEL and returns the previous interrupt status.
intr_level
Interrupts on or off?
struct list_elem * list_pop_front(struct list *list)
Removes the front element from LIST and returns it.
bool list_empty(struct list *list)
Returns true if LIST is empty, false otherwise.
void list_init(struct list *list)
Initializes LIST as an empty list.
void list_push_back(struct list *list, struct list_elem *elem)
Inserts ELEM at the end of LIST, so that it becomes the back in LIST.
int printf(const char *format,...)
Writes formatted output to the console.
#define list_entry(LIST_ELEM, STRUCT, MEMBER)
Converts pointer to list element LIST_ELEM into a pointer to the structure that LIST_ELEM is embedded...
static struct semaphore sema
struct list waiters
List of waiting threads.
struct thread * holder
Thread holding lock (for debugging).
struct semaphore semaphore
Binary semaphore controlling access.
struct list_elem elem
List element.
struct semaphore semaphore
This semaphore.
unsigned value
Current value.
struct list waiters
List of waiting threads.
A kernel thread or user process.
void lock_release(struct lock *lock)
Releases LOCK, which must be owned by the current thread.
void sema_init(struct semaphore *sema, unsigned value)
This file is derived from source code for the Nachos instructional operating system.
bool sema_try_down(struct semaphore *sema)
Down or "P" operation on a semaphore, but only if the semaphore is not already 0.
bool lock_try_acquire(struct lock *lock)
Tries to acquires LOCK and returns true if successful or false on failure.
bool lock_held_by_current_thread(const struct lock *lock)
Returns true if the current thread holds LOCK, false otherwise.
void cond_wait(struct condition *cond, struct lock *lock)
Atomically releases LOCK and waits for COND to be signaled by some other piece of code.
void cond_signal(struct condition *cond, struct lock *lock UNUSED)
If any threads are waiting on COND (protected by LOCK), then this function signals one of them to wak...
static void sema_test_helper(void *sema_)
Thread function used by sema_self_test().
void sema_up(struct semaphore *sema)
Up or "V" operation on a semaphore.
void lock_init(struct lock *lock)
Initializes LOCK.
void lock_acquire(struct lock *lock)
Acquires LOCK, sleeping until it becomes available if necessary.
void cond_broadcast(struct condition *cond, struct lock *lock)
Wakes up all threads, if any, waiting on COND (protected by LOCK).
void sema_self_test(void)
Self-test for semaphores that makes control "ping-pong" between a pair of threads.
void sema_down(struct semaphore *sema)
Down or "P" operation on a semaphore.
void cond_init(struct condition *cond)
Initializes condition variable COND.
struct thread * thread_current(void)
Returns the running thread.
void thread_unblock(struct thread *t)
Transitions a blocked thread T to the ready-to-run state.
tid_t thread_create(const char *name, int priority, thread_func *function, void *aux)
Creates a new kernel thread named NAME with the given initial PRIORITY, which executes FUNCTION passi...
void thread_block(void)
Puts the current thread to sleep.
#define PRI_DEFAULT
Default priority.