mirror of
https://github.com/AfonsoCMSousa/Thread-Master.git
synced 2026-05-14 05:48:36 +01:00
Compare commits
No commits in common. "master" and "v1.0" have entirely different histories.
10
README.md
10
README.md
@ -7,8 +7,6 @@ Hey, I'm Afonso, a passionate developer who loves low-level C/C++ and even some
|
||||
I originally created this library as a proof-of-concept, but it quickly evolved into something much bigger.
|
||||
If you're interested in learning how it works, check out the [GUIDE.md](https://github.com/AfonsoCMSousa/Thread-Master/blob/master/GUIDE.md) and the `main.c` file, along with all the headers in the `include/` directory.
|
||||
|
||||
Of course! Feel free to create a new [issue](https://github.com/AfonsoCMSousa/Thread-Master/issues) if you ever find any when using the library.
|
||||
|
||||
---
|
||||
|
||||
## Features
|
||||
@ -39,8 +37,6 @@ Or compiple manually:
|
||||
gcc -o my_program src/main.c include/threadlib/threadlib.c -pthread
|
||||
```
|
||||
|
||||
Check the [releases](https://github.com/AfonsoCMSousa/Thread-Master/releases/latest) for a detailed instalation guide and some libraries (.a) (.dll) or even (.lib).
|
||||
|
||||
## All Available Functions
|
||||
|
||||
### thread_master_init
|
||||
@ -102,9 +98,9 @@ Assigns a new job to the thread workers.
|
||||
- `include/threadlib/threadlib.h`: Header file for the thread library.
|
||||
- `include/threadlib/threadlib.c`: Implementation of the thread library.
|
||||
|
||||
## A big thanks to:
|
||||
- Professor **Marco Ferreira**
|
||||
- Professor **Patrício Domingues**
|
||||
### A big thanks to:
|
||||
- Professor **Marco Ferreira** - <marco.ferreira@ipleiria.pt>
|
||||
- Professor **Patrício Domingues** - <patricio.domingues@ipleiria.pt>
|
||||
|
||||
## Licence:
|
||||
This content falls under [Apache License Version 2.0](https://github.com/AfonsoCMSousa/Thread-Master/blob/master/LICENSE)
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
#include "threadlib.h"
|
||||
#include "threadlib/threadlib.h"
|
||||
|
||||
int __max_threads;
|
||||
unsigned char isThreadMasterRunning = 0;
|
||||
@ -12,7 +12,7 @@ void __thread_mutex_init__(pthread_mutex_t *mutex)
|
||||
{
|
||||
if (pthread_mutex_init(mutex, NULL) != 0)
|
||||
{
|
||||
fprintf(stderr, "Thread Master - Error: Failed to initialize mutex.\n");
|
||||
fprintf(stderr, "Error: Failed to initialize mutex.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
@ -26,7 +26,7 @@ void __thread_mutex_destroy__(pthread_mutex_t *mutex)
|
||||
{
|
||||
if (pthread_mutex_destroy(mutex) != 0)
|
||||
{
|
||||
fprintf(stderr, "Thread Master - Error: Failed to destroy mutex.\n");
|
||||
fprintf(stderr, "Error: Failed to destroy mutex.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
@ -43,7 +43,7 @@ void *__thread_master_init__(void *params)
|
||||
listT = (thread *)malloc(param->max_threads * sizeof(thread));
|
||||
if (listT == NULL)
|
||||
{
|
||||
fprintf(stderr, "Thread Master - Error: Failed to allocate memory for thread pool.\n");
|
||||
fprintf(stderr, "Tread Master - Error: Failed to allocate memory for thread pool.\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -62,6 +62,22 @@ void *__thread_master_init__(void *params)
|
||||
printf("Thread Master - Success: Ready.\n");
|
||||
|
||||
thread_master_assign_new_job(param->__thread_worker__, param->custom_params);
|
||||
|
||||
/* for (int i = 0; i < param->max_threads; i++)
|
||||
{
|
||||
// 3 - Create the threads
|
||||
if (pthread_create(&(listT[i].thread), NULL, param->__thread_worker__, &(listT[i].worker_param)) != 0)
|
||||
{
|
||||
fprintf(stderr, "Error: Failed to create thread %d.\n", i + 1);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
listT[i].worker_param.status = BUSY;
|
||||
}
|
||||
|
||||
for (int i = 0; i < param->max_threads; i++)
|
||||
{
|
||||
pthread_join(listT[i].thread, NULL);
|
||||
}*/
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -81,7 +97,7 @@ void thread_master_init(int max_threads, void *(*__thread_worker__)(void *), voi
|
||||
|
||||
if (pthread_create(&thread_master, NULL, __thread_master_init__, (void *)param) != 0)
|
||||
{
|
||||
fprintf(stderr, "Thread Master - Error: Failed to create thread master.\n");
|
||||
fprintf(stderr, "Error: Failed to create thread master.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
isThreadMasterRunning = 1;
|
||||
@ -120,7 +136,7 @@ void thread_master_get_status()
|
||||
printf("Thread Master - Max Threads: %d\n", __max_threads);
|
||||
printf("Param: %d\n", param->max_threads);
|
||||
#endif // DEBUG
|
||||
sleep_ms(100);
|
||||
sleep(1);
|
||||
} while (__max_threads == 0);
|
||||
|
||||
pthread_mutex_lock(¶m->mutex);
|
||||
@ -171,4 +187,4 @@ void thread_master_free()
|
||||
free(param);
|
||||
free(listT);
|
||||
printf("Thread Master - Free and Stopped\n");
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user