more projects
This commit is contained in:
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 106 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 40 KiB |
Binary file not shown.
@@ -0,0 +1,96 @@
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
/* the list of integers */
|
||||
int *list;
|
||||
int num_of_args;
|
||||
|
||||
/* the threads will set these values */
|
||||
double average;
|
||||
int maximum;
|
||||
int minimum;
|
||||
|
||||
void *calculate_average(void *param);
|
||||
void *calculate_maximum(void *param);
|
||||
void *calculate_minimum(void *param);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
num_of_args = argc-1;
|
||||
pthread_t tid_1;
|
||||
pthread_t tid_2;
|
||||
pthread_t tid_3;
|
||||
|
||||
/* allocate memory to hold array of integers */
|
||||
list = malloc(sizeof(int)*num_of_args);
|
||||
|
||||
for (i = 0; i < num_of_args; i++)
|
||||
list[i] = atoi(argv[i+1]);
|
||||
|
||||
/* create the threads */
|
||||
//-------------[TO BE COMPLETED]-------------
|
||||
pthread_create(&tid_1, NULL, calculate_average, NULL);
|
||||
pthread_create(&tid_2, NULL, calculate_maximum, NULL);
|
||||
pthread_create(&tid_3, NULL, calculate_minimum, NULL);
|
||||
|
||||
/* wait for the threads to exit */
|
||||
//-------------[TO BE COMPLETED]-------------
|
||||
pthread_join(tid_1, NULL);
|
||||
pthread_join(tid_2, NULL);
|
||||
pthread_join(tid_3, NULL);
|
||||
|
||||
printf("The average is %f\n", average);
|
||||
printf("The maximum is %d\n", maximum);
|
||||
printf("The minimum is %d\n", minimum);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *calculate_average(void *param)
|
||||
{
|
||||
//-------------[TO BE COMPLETED]-------------
|
||||
double sum = 0.0;
|
||||
|
||||
for (int i = 0; i < num_of_args; i++)
|
||||
{
|
||||
sum += list[i];
|
||||
}
|
||||
|
||||
average = sum / num_of_args;
|
||||
pthread_exit(0);
|
||||
}
|
||||
|
||||
void *calculate_maximum(void *param)
|
||||
{
|
||||
//-------------[TO BE COMPLETED]-------------
|
||||
maximum = list[0];
|
||||
|
||||
for (int i = 1; i < num_of_args; i++)
|
||||
{
|
||||
if (list[i] > maximum)
|
||||
{
|
||||
maximum = list[i];
|
||||
}
|
||||
}
|
||||
|
||||
pthread_exit(0);
|
||||
}
|
||||
|
||||
void *calculate_minimum(void *param)
|
||||
{
|
||||
//-------------[TO BE COMPLETED]-------------
|
||||
minimum = list[0];
|
||||
|
||||
for (int i = 1; i < num_of_args; i++)
|
||||
{
|
||||
if (list[i] < minimum)
|
||||
{
|
||||
minimum = list[i];
|
||||
}
|
||||
}
|
||||
|
||||
pthread_exit(0);
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
/* the list of integers */
|
||||
int *list;
|
||||
|
||||
/* the threads will set these values */
|
||||
double average;
|
||||
int maximum;
|
||||
int minimum;
|
||||
|
||||
void *calculate_average(void *param);
|
||||
void *calculate_maximum(void *param);
|
||||
void *calculate_minimum(void *param);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
int num_of_args = argc-1;
|
||||
pthread_t tid_1;
|
||||
pthread_t tid_2;
|
||||
pthread_t tid_3;
|
||||
|
||||
/* allocate memory to hold array of integers */
|
||||
list = malloc(sizeof(int)*num_of_args);
|
||||
|
||||
for (i = 0; i < num_of_args; i++)
|
||||
list[i] = atoi(argv[i+1]);
|
||||
|
||||
/* create the threads */
|
||||
//-------------[TO BE COMPLETED]-------------
|
||||
pthread_create(&tid_1, NULL, calculate_average, NULL);
|
||||
pthread_create(&tid_2, NULL, calculate_maximum, NULL);
|
||||
pthread_create(&tid_3, NULL, calculate_minimum, NULL);
|
||||
|
||||
/* wait for the threads to exit */
|
||||
//-------------[TO BE COMPLETED]-------------
|
||||
pthread_join(tid_1, NULL);
|
||||
pthread_join(tid_2, NULL);
|
||||
pthread_join(tid_3, NULL);
|
||||
|
||||
printf("The average is %f\n", average);
|
||||
printf("The maximum is %d\n", maximum);
|
||||
printf("The minimum is %d\n", minimum);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *calculate_average(void *param)
|
||||
{
|
||||
//-------------[TO BE COMPLETED]-------------
|
||||
double sum = 0.0;
|
||||
int num_of_args = argc - 1;
|
||||
|
||||
for (int i = 0; i < num_of_args; i++)
|
||||
{
|
||||
sum += list[i];
|
||||
}
|
||||
|
||||
average = sum / num_of_args;
|
||||
pthread_exit(0);
|
||||
}
|
||||
|
||||
void *calculate_maximum(void *param)
|
||||
{
|
||||
//-------------[TO BE COMPLETED]-------------
|
||||
int num_of_args = argc - 1;
|
||||
maximum = list[0];
|
||||
|
||||
for (int i = 1; i < num_of_args; i++)
|
||||
{
|
||||
if (list[i] > maximum)
|
||||
{
|
||||
maximum = list[i];
|
||||
}
|
||||
}
|
||||
|
||||
pthread_exit(0);
|
||||
}
|
||||
|
||||
void *calculate_minimum(void *param)
|
||||
{
|
||||
//-------------[TO BE COMPLETED]-------------
|
||||
int num_of_args = argc - 1;
|
||||
minimum = list[0];
|
||||
|
||||
for (int i = 1; i < num_of_args; i++)
|
||||
{
|
||||
if (list[i] < minimum)
|
||||
{
|
||||
minimum = list[i];
|
||||
}
|
||||
}
|
||||
|
||||
pthread_exit(0);
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define SIZE 10
|
||||
#define NUMBER_OF_THREADS 3
|
||||
|
||||
void *sorter(void *params); /* thread that performs basic sorting algorithm */
|
||||
void *merger(void *params); /* thread that performs merging of results */
|
||||
|
||||
int list[SIZE] = {7,12,19,3,18,4,2,6,15,8};
|
||||
|
||||
int result[SIZE];
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int from_index;
|
||||
int to_index;
|
||||
} parameters;
|
||||
|
||||
int main (int argc, const char * argv[])
|
||||
{
|
||||
int i;
|
||||
|
||||
pthread_t workers[NUMBER_OF_THREADS];
|
||||
|
||||
/* establish the first sorting thread */
|
||||
parameters *data = (parameters *) malloc (sizeof(parameters));
|
||||
data->from_index = 0;
|
||||
data->to_index = (SIZE/2) - 1;
|
||||
pthread_create(&workers[0], 0, sorter, data);
|
||||
|
||||
/* establish the second sorting thread */
|
||||
data = (parameters *) malloc (sizeof(parameters));
|
||||
data->from_index = SIZE/2;
|
||||
data->to_index = SIZE - 1;
|
||||
pthread_create(&workers[1], 0, sorter, data);
|
||||
|
||||
/* now wait for the 2 sorting threads to finish */
|
||||
for(i = 0; i < NUMBER_OF_THREADS - 1; i++)
|
||||
pthread_join(workers[i], NULL);
|
||||
|
||||
/* establish the merge thread */
|
||||
data = (parameters *) malloc(sizeof(parameters));
|
||||
data->from_index = 0;
|
||||
data->to_index = SIZE/2;
|
||||
pthread_create(&workers[2], 0, merger, data);
|
||||
|
||||
/* wait for the merge thread to finish */
|
||||
pthread_join(workers[2], NULL);
|
||||
|
||||
/* output the sorted array */
|
||||
for (i = 0; i < SIZE; i++)
|
||||
printf("%d ",result[i]);
|
||||
printf("\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorting thread.
|
||||
*
|
||||
* This thread can essentially use any algorithm for sorting
|
||||
*/
|
||||
|
||||
void *sorter(void *params)
|
||||
{
|
||||
int i,j,temp;
|
||||
parameters* p = (parameters *)params;
|
||||
|
||||
int begin = p->from_index;
|
||||
int end = p->to_index;
|
||||
|
||||
// simple bubble sort
|
||||
for(i=begin;i<=end;i++){
|
||||
for(j=i+1;j<=end;j++){
|
||||
if(list[i]>list[j]){
|
||||
temp=list[i];
|
||||
list[i]=list[j];
|
||||
list[j]=temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pthread_exit(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge thread
|
||||
*
|
||||
* Uses simple merge sort for merging two sublists
|
||||
*/
|
||||
|
||||
void *merger(void *params)
|
||||
{
|
||||
parameters* p = (parameters *)params;
|
||||
|
||||
int i,j;
|
||||
|
||||
i = p->from_index;
|
||||
j = p->to_index;
|
||||
|
||||
int position = 0; /* position being inserted into result list */
|
||||
|
||||
while (i < p->to_index && j < SIZE) {
|
||||
if (list[i] <= list[j]) {
|
||||
result[position++] = list[i];
|
||||
i++;
|
||||
}
|
||||
else {
|
||||
result[position++] = list[j];
|
||||
j++;
|
||||
}
|
||||
}
|
||||
|
||||
/* copy the remainder */
|
||||
if (i < p->to_index) {
|
||||
while (i < p->to_index) {
|
||||
result[position] = list[i];
|
||||
position++;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
while (j < SIZE) {
|
||||
result[position] = list[j];
|
||||
position++;
|
||||
j++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
pthread_exit(0);
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
//CS 321: Skeleton code for multithreaded sorting program
|
||||
//Feel free to modify the code as you wish.
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define SIZE 10
|
||||
#define NUMBER_OF_THREADS 3
|
||||
|
||||
void *sorter(void *params); /* thread that performs basic sorting algorithm */
|
||||
void *merger(void *params); /* thread that performs merging of results */
|
||||
|
||||
int list[SIZE] = {7,12,19,3,18,4,2,6,15,8};
|
||||
|
||||
int result[SIZE];
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int from_index;
|
||||
int to_index;
|
||||
} parameters;
|
||||
|
||||
int main (int argc, const char * argv[])
|
||||
{
|
||||
int i;
|
||||
|
||||
pthread_t workers[NUMBER_OF_THREADS];
|
||||
|
||||
/* establish the first sorting thread */
|
||||
parameters *data = (parameters *) malloc (sizeof(parameters));
|
||||
data->from_index = 0;
|
||||
data->to_index = (SIZE/2) - 1;
|
||||
pthread_create(&workers[0], 0, sorter, data);
|
||||
|
||||
/* establish the second sorting thread */
|
||||
//-------------[TO BE COMPLETED]-------------
|
||||
|
||||
|
||||
/* now wait for the 2 sorting threads to finish */
|
||||
//-------------[TO BE COMPLETED]-------------
|
||||
|
||||
|
||||
/* establish the merge thread */
|
||||
//-------------[TO BE COMPLETED]-------------
|
||||
|
||||
|
||||
/* wait for the merge thread to finish */
|
||||
//-------------[TO BE COMPLETED]-------------
|
||||
|
||||
/* output the sorted array */
|
||||
for (i = 0; i < SIZE; i++)
|
||||
printf("%d ",result[i]);
|
||||
printf("\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorting thread.
|
||||
*
|
||||
* This thread can essentially use any algorithm for sorting
|
||||
*/
|
||||
|
||||
void *sorter(void *params)
|
||||
{
|
||||
int i;
|
||||
parameters* p = (parameters *)params;
|
||||
|
||||
int begin = p->from_index;
|
||||
int end = p->to_index;
|
||||
|
||||
//-------------[TO BE COMPLETED]-------------
|
||||
|
||||
pthread_exit(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Merge thread
|
||||
*
|
||||
* Uses simple merge sort for merging two sublists
|
||||
*/
|
||||
|
||||
void *merger(void *params)
|
||||
{
|
||||
parameters* p = (parameters *)params;
|
||||
|
||||
int i,j;
|
||||
|
||||
i = p->from_index;
|
||||
j = p->to_index;
|
||||
|
||||
int position = 0; /* position being inserted into result list */
|
||||
|
||||
while (i < p->to_index && j < SIZE) {
|
||||
if (list[i] <= list[j]) {
|
||||
result[position++] = list[i];
|
||||
i++;
|
||||
}
|
||||
else {
|
||||
result[position++] = list[j];
|
||||
j++;
|
||||
}
|
||||
}
|
||||
|
||||
/* copy the remainder */
|
||||
if (i < p->to_index) {
|
||||
while (i < p->to_index) {
|
||||
result[position] = list[i];
|
||||
position++;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
while (j < SIZE) {
|
||||
result[position] = list[j];
|
||||
position++;
|
||||
j++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
pthread_exit(0);
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,37 @@
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int sum;
|
||||
void *runner(void *param);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
pthread_t tid;
|
||||
pthread_attr_t attr;
|
||||
|
||||
|
||||
pthread_attr_init(&attr);
|
||||
printf("Thread Created\n");
|
||||
|
||||
pthread_create(&tid, &attr, runner, argv[1]);
|
||||
|
||||
printf("Parent, wait for child thread\n");
|
||||
pthread_join(tid, NULL);
|
||||
|
||||
printf("sum = %d\n", sum);
|
||||
printf("done\n");
|
||||
}
|
||||
|
||||
void *runner(void *param)
|
||||
{
|
||||
int i, upper = atoi(param);
|
||||
sum = 0;
|
||||
|
||||
for (i =1 ; i <= upper; i++) {
|
||||
sum +=i;
|
||||
}
|
||||
|
||||
printf("Terminate child thread\n");
|
||||
return(0);
|
||||
}
|
||||
@@ -0,0 +1,284 @@
|
||||
// !$*UTF8*$!
|
||||
{
|
||||
archiveVersion = 1;
|
||||
classes = {
|
||||
};
|
||||
objectVersion = 56;
|
||||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
266B671C2AE17C9D005614D6 /* main.c in Sources */ = {isa = PBXBuildFile; fileRef = 266B671B2AE17C9D005614D6 /* main.c */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXCopyFilesBuildPhase section */
|
||||
266B67162AE17C9D005614D6 /* CopyFiles */ = {
|
||||
isa = PBXCopyFilesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
dstPath = /usr/share/man/man1/;
|
||||
dstSubfolderSpec = 0;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 1;
|
||||
};
|
||||
/* End PBXCopyFilesBuildPhase section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
266B67182AE17C9D005614D6 /* test */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = test; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
266B671B2AE17C9D005614D6 /* main.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = main.c; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
266B67152AE17C9D005614D6 /* Frameworks */ = {
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXFrameworksBuildPhase section */
|
||||
|
||||
/* Begin PBXGroup section */
|
||||
266B670F2AE17C9D005614D6 = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
266B671A2AE17C9D005614D6 /* test */,
|
||||
266B67192AE17C9D005614D6 /* Products */,
|
||||
);
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
266B67192AE17C9D005614D6 /* Products */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
266B67182AE17C9D005614D6 /* test */,
|
||||
);
|
||||
name = Products;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
266B671A2AE17C9D005614D6 /* test */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
266B671B2AE17C9D005614D6 /* main.c */,
|
||||
);
|
||||
path = test;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXGroup section */
|
||||
|
||||
/* Begin PBXNativeTarget section */
|
||||
266B67172AE17C9D005614D6 /* test */ = {
|
||||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = 266B671F2AE17C9D005614D6 /* Build configuration list for PBXNativeTarget "test" */;
|
||||
buildPhases = (
|
||||
266B67142AE17C9D005614D6 /* Sources */,
|
||||
266B67152AE17C9D005614D6 /* Frameworks */,
|
||||
266B67162AE17C9D005614D6 /* CopyFiles */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
dependencies = (
|
||||
);
|
||||
name = test;
|
||||
productName = test;
|
||||
productReference = 266B67182AE17C9D005614D6 /* test */;
|
||||
productType = "com.apple.product-type.tool";
|
||||
};
|
||||
/* End PBXNativeTarget section */
|
||||
|
||||
/* Begin PBXProject section */
|
||||
266B67102AE17C9D005614D6 /* Project object */ = {
|
||||
isa = PBXProject;
|
||||
attributes = {
|
||||
BuildIndependentTargetsInParallel = 1;
|
||||
LastUpgradeCheck = 1500;
|
||||
TargetAttributes = {
|
||||
266B67172AE17C9D005614D6 = {
|
||||
CreatedOnToolsVersion = 15.0;
|
||||
};
|
||||
};
|
||||
};
|
||||
buildConfigurationList = 266B67132AE17C9D005614D6 /* Build configuration list for PBXProject "test" */;
|
||||
compatibilityVersion = "Xcode 14.0";
|
||||
developmentRegion = en;
|
||||
hasScannedForEncodings = 0;
|
||||
knownRegions = (
|
||||
en,
|
||||
Base,
|
||||
);
|
||||
mainGroup = 266B670F2AE17C9D005614D6;
|
||||
productRefGroup = 266B67192AE17C9D005614D6 /* Products */;
|
||||
projectDirPath = "";
|
||||
projectRoot = "";
|
||||
targets = (
|
||||
266B67172AE17C9D005614D6 /* test */,
|
||||
);
|
||||
};
|
||||
/* End PBXProject section */
|
||||
|
||||
/* Begin PBXSourcesBuildPhase section */
|
||||
266B67142AE17C9D005614D6 /* Sources */ = {
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
266B671C2AE17C9D005614D6 /* main.c in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXSourcesBuildPhase section */
|
||||
|
||||
/* Begin XCBuildConfiguration section */
|
||||
266B671D2AE17C9D005614D6 /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
|
||||
CLANG_ANALYZER_NONNULL = YES;
|
||||
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CLANG_ENABLE_OBJC_ARC = YES;
|
||||
CLANG_ENABLE_OBJC_WEAK = YES;
|
||||
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
|
||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||
CLANG_WARN_COMMA = YES;
|
||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
|
||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
|
||||
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
|
||||
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
|
||||
CLANG_WARN_STRICT_PROTOTYPES = YES;
|
||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
||||
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
COPY_PHASE_STRIP = NO;
|
||||
DEBUG_INFORMATION_FORMAT = dwarf;
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||
ENABLE_TESTABILITY = YES;
|
||||
ENABLE_USER_SCRIPT_SANDBOXING = YES;
|
||||
GCC_C_LANGUAGE_STANDARD = gnu17;
|
||||
GCC_DYNAMIC_NO_PIC = NO;
|
||||
GCC_NO_COMMON_BLOCKS = YES;
|
||||
GCC_OPTIMIZATION_LEVEL = 0;
|
||||
GCC_PREPROCESSOR_DEFINITIONS = (
|
||||
"DEBUG=1",
|
||||
"$(inherited)",
|
||||
);
|
||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
||||
GCC_WARN_UNDECLARED_SELECTOR = YES;
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
|
||||
MACOSX_DEPLOYMENT_TARGET = 14.0;
|
||||
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
|
||||
MTL_FAST_MATH = YES;
|
||||
ONLY_ACTIVE_ARCH = YES;
|
||||
SDKROOT = macosx;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
266B671E2AE17C9D005614D6 /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
|
||||
CLANG_ANALYZER_NONNULL = YES;
|
||||
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CLANG_ENABLE_OBJC_ARC = YES;
|
||||
CLANG_ENABLE_OBJC_WEAK = YES;
|
||||
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
|
||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||
CLANG_WARN_COMMA = YES;
|
||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
|
||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
|
||||
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
|
||||
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
|
||||
CLANG_WARN_STRICT_PROTOTYPES = YES;
|
||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
||||
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
COPY_PHASE_STRIP = NO;
|
||||
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
||||
ENABLE_NS_ASSERTIONS = NO;
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||
ENABLE_USER_SCRIPT_SANDBOXING = YES;
|
||||
GCC_C_LANGUAGE_STANDARD = gnu17;
|
||||
GCC_NO_COMMON_BLOCKS = YES;
|
||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
||||
GCC_WARN_UNDECLARED_SELECTOR = YES;
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
|
||||
MACOSX_DEPLOYMENT_TARGET = 14.0;
|
||||
MTL_ENABLE_DEBUG_INFO = NO;
|
||||
MTL_FAST_MATH = YES;
|
||||
SDKROOT = macosx;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
266B67202AE17C9D005614D6 /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
266B67212AE17C9D005614D6 /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
/* End XCBuildConfiguration section */
|
||||
|
||||
/* Begin XCConfigurationList section */
|
||||
266B67132AE17C9D005614D6 /* Build configuration list for PBXProject "test" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
266B671D2AE17C9D005614D6 /* Debug */,
|
||||
266B671E2AE17C9D005614D6 /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
266B671F2AE17C9D005614D6 /* Build configuration list for PBXNativeTarget "test" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
266B67202AE17C9D005614D6 /* Debug */,
|
||||
266B67212AE17C9D005614D6 /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
/* End XCConfigurationList section */
|
||||
};
|
||||
rootObject = 266B67102AE17C9D005614D6 /* Project object */;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Workspace
|
||||
version = "1.0">
|
||||
<FileRef
|
||||
location = "self:">
|
||||
</FileRef>
|
||||
</Workspace>
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>IDEDidComputeMac32BitWarning</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
||||
BIN
Binary file not shown.
+14
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>SchemeUserState</key>
|
||||
<dict>
|
||||
<key>test.xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>0</integer>
|
||||
</dict>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1,98 @@
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
/* the list of integers */
|
||||
int *list;
|
||||
|
||||
/* the threads will set these values */
|
||||
double average;
|
||||
int maximum;
|
||||
int minimum;
|
||||
|
||||
void *calculate_average(void *param);
|
||||
void *calculate_maximum(void *param);
|
||||
void *calculate_minimum(void *param);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
int num_of_args = argc-1;
|
||||
pthread_t tid_1;
|
||||
pthread_t tid_2;
|
||||
pthread_t tid_3;
|
||||
|
||||
/* allocate memory to hold array of integers */
|
||||
list = malloc(sizeof(int)*num_of_args);
|
||||
|
||||
for (i = 0; i < num_of_args; i++)
|
||||
list[i] = atoi(argv[i+1]);
|
||||
|
||||
/* create the threads */
|
||||
//-------------[TO BE COMPLETED]-------------
|
||||
pthread_create(&tid_1, NULL, calculate_average, NULL);
|
||||
pthread_create(&tid_2, NULL, calculate_maximum, NULL);
|
||||
pthread_create(&tid_3, NULL, calculate_minimum, NULL);
|
||||
|
||||
/* wait for the threads to exit */
|
||||
//-------------[TO BE COMPLETED]-------------
|
||||
pthread_join(tid_1, NULL);
|
||||
pthread_join(tid_2, NULL);
|
||||
pthread_join(tid_3, NULL);
|
||||
|
||||
printf("The average is %f\n", average);
|
||||
printf("The maximum is %d\n", maximum);
|
||||
printf("The minimum is %d\n", minimum);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *calculate_average(void *param)
|
||||
{
|
||||
//-------------[TO BE COMPLETED]-------------
|
||||
double sum = 0.0;
|
||||
int num_of_args = argc - 1;
|
||||
|
||||
for (int i = 0; i < num_of_args; i++)
|
||||
{
|
||||
sum += list[i];
|
||||
}
|
||||
|
||||
average = sum / num_of_args;
|
||||
pthread_exit(0);
|
||||
}
|
||||
|
||||
void *calculate_maximum(void *param)
|
||||
{
|
||||
//-------------[TO BE COMPLETED]-------------
|
||||
int num_of_args = argc - 1;
|
||||
maximum = list[0];
|
||||
|
||||
for (int i = 1; i < num_of_args; i++)
|
||||
{
|
||||
if (list[i] > maximum)
|
||||
{
|
||||
maximum = list[i];
|
||||
}
|
||||
}
|
||||
|
||||
pthread_exit(0);
|
||||
}
|
||||
|
||||
void *calculate_minimum(void *param)
|
||||
{
|
||||
//-------------[TO BE COMPLETED]-------------
|
||||
int num_of_args = argc - 1;
|
||||
minimum = list[0];
|
||||
|
||||
for (int i = 1; i < num_of_args; i++)
|
||||
{
|
||||
if (list[i] < minimum)
|
||||
{
|
||||
minimum = list[i];
|
||||
}
|
||||
}
|
||||
|
||||
pthread_exit(0);
|
||||
}
|
||||
Reference in New Issue
Block a user