Local worker

This commit is contained in:
Adrien Bourmault 2021-06-11 14:07:13 +02:00
parent 4219ae2888
commit 2924428bdf
No known key found for this signature in database
GPG Key ID: 6EB408FE0ACEC664
2 changed files with 52 additions and 0 deletions

View File

@ -23,4 +23,21 @@
#include "../include/base.h" #include "../include/base.h"
#endif #endif
pthread_t *WorkerInit(SchedulerParams_t *parameters);
// -------------------------------------------------------------------------- //
// Scheduler destructor function //
// -------------------------------------------------------------------------- //
static inline int WorkerDestroy(pthread_t *schedThread)
{
free(schedThread);
return 0;
}
// -------------------------------------------------------------------------- //
// Scheduler wait function //
// -------------------------------------------------------------------------- //
static inline void WorkerWait(pthread_t *schedThread)
{
pthread_join(*schedThread, NULL);
}

View File

@ -18,3 +18,38 @@
// You should have received a copy of the GNU Affero General Public License // // You should have received a copy of the GNU Affero General Public License //
// along with this program. If not, see <https://www.gnu.org/licenses/>. // // along with this program. If not, see <https://www.gnu.org/licenses/>. //
//=-------------------------------------------------------------------------=// //=-------------------------------------------------------------------------=//
#include "../include/base.h"
static void *LittleWorker(void *parameters);
/* -------------------------------------------------------------------------- */
// -------------------------------------------------------------------------- //
// Scheduler init function //
// -------------------------------------------------------------------------- //
pthread_t *WorkerInit(SchedulerParams_t *parameters)
{
parameters->id = (pthread_t*) malloc(sizeof(pthread_t));
pthread_create(parameters->id, NULL, LittleWorker, parameters);
return parameters->id;
}
// -------------------------------------------------------------------------- //
// Scheduler thread main function //
// -------------------------------------------------------------------------- //
static void *LittleWorker(void *params)
{
SchedulerParams_t *parameters = (SchedulerParams_t*) params;
int a = 4;
for (int i = 0; i < 45000; i++) {
for (int j = i; j < 45000; j++) {
a = (a + (long)parameters->id) * i * j;
}
}
printf("thread %d\n", a);
return NULL;
}