Skip to content

Commit

Permalink
Merge remote-tracking branch 'assignments-base/assignment4'
Browse files Browse the repository at this point in the history
  • Loading branch information
tale1433 committed Sep 21, 2024
2 parents 4037870 + e485aee commit 34af924
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 12 deletions.
9 changes: 0 additions & 9 deletions .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,3 @@ jobs:
run : git submodule update --init --recursive
- name: Run unit test
run: ./unit-test.sh
full-test:
container: cuaesd/aesd-autotest:24-assignment3
runs-on: self-hosted
steps:
- uses: actions/checkout@v2
- name: Checkout submodules
run : git submodule update --init --recursive
- name: Run full test
run: ./full-test.sh
7 changes: 5 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ project(aesd-assignments)
# At minimum it should include the files in the test/assignmentX directory
# Students can also add paths to their own test files using a ../ prefix to
# reference this working directory

set(CMAKE_C_FLAGS "-pthread")

set(AUTOTEST_SOURCES
test/assignment1/Test_hello.c
test/assignment1/Test_assignment_validate.c
test/assignment3/Test_systemcalls.c
test/assignment4/Test_threading.c
)
# A list of all files containing test code that is used for assignment validation
set(TESTED_SOURCE
../examples/autotest-validate/autotest-validate.c
../examples/systemcalls/systemcalls.c
../examples/threading/threading.c
)
add_subdirectory(assignment-autotest)
2 changes: 1 addition & 1 deletion conf/assignment.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
assignment3
assignment4
33 changes: 33 additions & 0 deletions examples/threading/threading.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "threading.h"
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>

// Optional: use these functions to add debug or error prints to your application
#define DEBUG_LOG(msg,...)
//#define DEBUG_LOG(msg,...) printf("threading: " msg "\n" , ##__VA_ARGS__)
#define ERROR_LOG(msg,...) printf("threading ERROR: " msg "\n" , ##__VA_ARGS__)

void* threadfunc(void* thread_param)
{

// TODO: wait, obtain mutex, wait, release mutex as described by thread_data structure
// hint: use a cast like the one below to obtain thread arguments from your parameter
//struct thread_data* thread_func_args = (struct thread_data *) thread_param;
return thread_param;
}


bool start_thread_obtaining_mutex(pthread_t *thread, pthread_mutex_t *mutex,int wait_to_obtain_ms, int wait_to_release_ms)
{
/**
* TODO: allocate memory for thread_data, setup mutex and wait arguments, pass thread_data to created thread
* using threadfunc() as entry point.
*
* return true if successful.
*
* See implementation details in threading.h file comment block
*/
return false;
}

40 changes: 40 additions & 0 deletions examples/threading/threading.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <stdbool.h>
#include <pthread.h>

/**
* This structure should be dynamically allocated and passed as
* an argument to your thread using pthread_create.
* It should be returned by your thread so it can be freed by
* the joiner thread.
*/
struct thread_data{
/*
* TODO: add other values your thread will need to manage
* into this structure, use this structure to communicate
* between the start_thread_obtaining_mutex function and
* your thread implementation.
*/

/**
* Set to true if the thread completed with success, false
* if an error occurred.
*/
bool thread_complete_success;
};


/**
* Start a thread which sleeps @param wait_to_obtain_ms number of milliseconds, then obtains the
* mutex in @param mutex, then holds for @param wait_to_release_ms milliseconds, then releases.
* The start_thread_obtaining_mutex function should only start the thread and should not block
* for the thread to complete.
* The start_thread_obtaining_mutex function should use dynamic memory allocation for thread_data
* structure passed into the thread. The number of threads active should be limited only by the
* amount of available memory.
* The thread started should return a pointer to the thread_data structure when it exits, which can be used
* to free memory as well as to check thread_complete_success for successful exit.
* If a thread was started succesfully @param thread should be filled with the pthread_create thread ID
* coresponding to the thread which was started.
* @return true if the thread could be started, false if a failure occurred.
*/
bool start_thread_obtaining_mutex(pthread_t *thread, pthread_mutex_t *mutex,int wait_to_obtain_ms, int wait_to_release_ms);

0 comments on commit 34af924

Please sign in to comment.