Real time task (periodic task)












0














Good evening everyone,



I'm still learning real-time programming, and I'm trying to synchronize two threads using semaphores, the first thread calculates the sum and returns a value (sum). the sum will be passed as a parameter to the 2nd thread that will use it to calculate an average (this is just an example for manipulating semaphores). my problem now and that the two tasks are not periodic because once the thread returns a result it leaves the loop while and the main() finishes the work !!! now how to make the tasks period ?? thank you for helping me and here is my source code.



  #include <stdio.h> 
#include <stdlib.h>
#include <pthread.h>
#include <semaphore.h>

sem_t evt;

//first task
void *tache1(void *arg)
{

int j;
int s=0;

struct timespec time;
clock_gettime(CLOCK_REALTIME, &time);

while(1){

printf("first THREADDDDDDDDD n");

for(j=0; j<100; j++)
s= s + j;


return (void*) s;
sem_post(&evt);

sleep(3);

}
}

//second task

void *tache2(void *arg){

int moyenne = 1;
int sum = *((int*) arg);

struct timespec time;
clock_gettime(CLOCK_REALTIME, &time);

while(3){

sem_wait(&evt);

printf("second THREADDDDDDDDD n");
moyenne= sum/10;

return(void*)moyenne;

sleep(2);

}
}

int main()
{
pthread_t th1, th2;
int sum;
int moyenne;

int status;
sem_init(&evt, 0,0);
printf("start mainn") ;

pthread_create(&th1, NULL, tache1, NULL);
pthread_join(th1, (void*) &sum);


pthread_create(&th2, NULL, tache2, &sum);
pthread_join(th2, (void*) &moyenne);

printf("the sum in the main is %d.n", sum);
printf("AVG %d.n", moyenne);
printf("End mainn") ;

return 0;
}









share|improve this question
























  • Take a closer look at the code now that it's formatted. The main issue should be apparent.
    – dbush
    Dec 27 '18 at 20:15






  • 2




    Also, pthread_create immediately followed by pthread_join means you're not really multithreading because you start the thread then wait for it to finish before continuing.
    – dbush
    Dec 27 '18 at 20:17












  • Yes but when i make "pthread_join" after "pthread_create" the execution will be blocked!!!
    – ikram
    Dec 27 '18 at 20:25










  • The way you have things written now, th1 has to finish before you even start th2. That's not multithreading.
    – dbush
    Dec 27 '18 at 20:27










  • Note also that the return statement causes the current function to return immediately. It doesn't just keep going.
    – dbush
    Dec 27 '18 at 20:29
















0














Good evening everyone,



I'm still learning real-time programming, and I'm trying to synchronize two threads using semaphores, the first thread calculates the sum and returns a value (sum). the sum will be passed as a parameter to the 2nd thread that will use it to calculate an average (this is just an example for manipulating semaphores). my problem now and that the two tasks are not periodic because once the thread returns a result it leaves the loop while and the main() finishes the work !!! now how to make the tasks period ?? thank you for helping me and here is my source code.



  #include <stdio.h> 
#include <stdlib.h>
#include <pthread.h>
#include <semaphore.h>

sem_t evt;

//first task
void *tache1(void *arg)
{

int j;
int s=0;

struct timespec time;
clock_gettime(CLOCK_REALTIME, &time);

while(1){

printf("first THREADDDDDDDDD n");

for(j=0; j<100; j++)
s= s + j;


return (void*) s;
sem_post(&evt);

sleep(3);

}
}

//second task

void *tache2(void *arg){

int moyenne = 1;
int sum = *((int*) arg);

struct timespec time;
clock_gettime(CLOCK_REALTIME, &time);

while(3){

sem_wait(&evt);

printf("second THREADDDDDDDDD n");
moyenne= sum/10;

return(void*)moyenne;

sleep(2);

}
}

int main()
{
pthread_t th1, th2;
int sum;
int moyenne;

int status;
sem_init(&evt, 0,0);
printf("start mainn") ;

pthread_create(&th1, NULL, tache1, NULL);
pthread_join(th1, (void*) &sum);


pthread_create(&th2, NULL, tache2, &sum);
pthread_join(th2, (void*) &moyenne);

printf("the sum in the main is %d.n", sum);
printf("AVG %d.n", moyenne);
printf("End mainn") ;

return 0;
}









share|improve this question
























  • Take a closer look at the code now that it's formatted. The main issue should be apparent.
    – dbush
    Dec 27 '18 at 20:15






  • 2




    Also, pthread_create immediately followed by pthread_join means you're not really multithreading because you start the thread then wait for it to finish before continuing.
    – dbush
    Dec 27 '18 at 20:17












  • Yes but when i make "pthread_join" after "pthread_create" the execution will be blocked!!!
    – ikram
    Dec 27 '18 at 20:25










  • The way you have things written now, th1 has to finish before you even start th2. That's not multithreading.
    – dbush
    Dec 27 '18 at 20:27










  • Note also that the return statement causes the current function to return immediately. It doesn't just keep going.
    – dbush
    Dec 27 '18 at 20:29














0












0








0







Good evening everyone,



I'm still learning real-time programming, and I'm trying to synchronize two threads using semaphores, the first thread calculates the sum and returns a value (sum). the sum will be passed as a parameter to the 2nd thread that will use it to calculate an average (this is just an example for manipulating semaphores). my problem now and that the two tasks are not periodic because once the thread returns a result it leaves the loop while and the main() finishes the work !!! now how to make the tasks period ?? thank you for helping me and here is my source code.



  #include <stdio.h> 
#include <stdlib.h>
#include <pthread.h>
#include <semaphore.h>

sem_t evt;

//first task
void *tache1(void *arg)
{

int j;
int s=0;

struct timespec time;
clock_gettime(CLOCK_REALTIME, &time);

while(1){

printf("first THREADDDDDDDDD n");

for(j=0; j<100; j++)
s= s + j;


return (void*) s;
sem_post(&evt);

sleep(3);

}
}

//second task

void *tache2(void *arg){

int moyenne = 1;
int sum = *((int*) arg);

struct timespec time;
clock_gettime(CLOCK_REALTIME, &time);

while(3){

sem_wait(&evt);

printf("second THREADDDDDDDDD n");
moyenne= sum/10;

return(void*)moyenne;

sleep(2);

}
}

int main()
{
pthread_t th1, th2;
int sum;
int moyenne;

int status;
sem_init(&evt, 0,0);
printf("start mainn") ;

pthread_create(&th1, NULL, tache1, NULL);
pthread_join(th1, (void*) &sum);


pthread_create(&th2, NULL, tache2, &sum);
pthread_join(th2, (void*) &moyenne);

printf("the sum in the main is %d.n", sum);
printf("AVG %d.n", moyenne);
printf("End mainn") ;

return 0;
}









share|improve this question















Good evening everyone,



I'm still learning real-time programming, and I'm trying to synchronize two threads using semaphores, the first thread calculates the sum and returns a value (sum). the sum will be passed as a parameter to the 2nd thread that will use it to calculate an average (this is just an example for manipulating semaphores). my problem now and that the two tasks are not periodic because once the thread returns a result it leaves the loop while and the main() finishes the work !!! now how to make the tasks period ?? thank you for helping me and here is my source code.



  #include <stdio.h> 
#include <stdlib.h>
#include <pthread.h>
#include <semaphore.h>

sem_t evt;

//first task
void *tache1(void *arg)
{

int j;
int s=0;

struct timespec time;
clock_gettime(CLOCK_REALTIME, &time);

while(1){

printf("first THREADDDDDDDDD n");

for(j=0; j<100; j++)
s= s + j;


return (void*) s;
sem_post(&evt);

sleep(3);

}
}

//second task

void *tache2(void *arg){

int moyenne = 1;
int sum = *((int*) arg);

struct timespec time;
clock_gettime(CLOCK_REALTIME, &time);

while(3){

sem_wait(&evt);

printf("second THREADDDDDDDDD n");
moyenne= sum/10;

return(void*)moyenne;

sleep(2);

}
}

int main()
{
pthread_t th1, th2;
int sum;
int moyenne;

int status;
sem_init(&evt, 0,0);
printf("start mainn") ;

pthread_create(&th1, NULL, tache1, NULL);
pthread_join(th1, (void*) &sum);


pthread_create(&th2, NULL, tache2, &sum);
pthread_join(th2, (void*) &moyenne);

printf("the sum in the main is %d.n", sum);
printf("AVG %d.n", moyenne);
printf("End mainn") ;

return 0;
}






c pthreads real-time semaphore






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 27 '18 at 20:16

























asked Dec 27 '18 at 20:05









ikram

32




32












  • Take a closer look at the code now that it's formatted. The main issue should be apparent.
    – dbush
    Dec 27 '18 at 20:15






  • 2




    Also, pthread_create immediately followed by pthread_join means you're not really multithreading because you start the thread then wait for it to finish before continuing.
    – dbush
    Dec 27 '18 at 20:17












  • Yes but when i make "pthread_join" after "pthread_create" the execution will be blocked!!!
    – ikram
    Dec 27 '18 at 20:25










  • The way you have things written now, th1 has to finish before you even start th2. That's not multithreading.
    – dbush
    Dec 27 '18 at 20:27










  • Note also that the return statement causes the current function to return immediately. It doesn't just keep going.
    – dbush
    Dec 27 '18 at 20:29


















  • Take a closer look at the code now that it's formatted. The main issue should be apparent.
    – dbush
    Dec 27 '18 at 20:15






  • 2




    Also, pthread_create immediately followed by pthread_join means you're not really multithreading because you start the thread then wait for it to finish before continuing.
    – dbush
    Dec 27 '18 at 20:17












  • Yes but when i make "pthread_join" after "pthread_create" the execution will be blocked!!!
    – ikram
    Dec 27 '18 at 20:25










  • The way you have things written now, th1 has to finish before you even start th2. That's not multithreading.
    – dbush
    Dec 27 '18 at 20:27










  • Note also that the return statement causes the current function to return immediately. It doesn't just keep going.
    – dbush
    Dec 27 '18 at 20:29
















Take a closer look at the code now that it's formatted. The main issue should be apparent.
– dbush
Dec 27 '18 at 20:15




Take a closer look at the code now that it's formatted. The main issue should be apparent.
– dbush
Dec 27 '18 at 20:15




2




2




Also, pthread_create immediately followed by pthread_join means you're not really multithreading because you start the thread then wait for it to finish before continuing.
– dbush
Dec 27 '18 at 20:17






Also, pthread_create immediately followed by pthread_join means you're not really multithreading because you start the thread then wait for it to finish before continuing.
– dbush
Dec 27 '18 at 20:17














Yes but when i make "pthread_join" after "pthread_create" the execution will be blocked!!!
– ikram
Dec 27 '18 at 20:25




Yes but when i make "pthread_join" after "pthread_create" the execution will be blocked!!!
– ikram
Dec 27 '18 at 20:25












The way you have things written now, th1 has to finish before you even start th2. That's not multithreading.
– dbush
Dec 27 '18 at 20:27




The way you have things written now, th1 has to finish before you even start th2. That's not multithreading.
– dbush
Dec 27 '18 at 20:27












Note also that the return statement causes the current function to return immediately. It doesn't just keep going.
– dbush
Dec 27 '18 at 20:29




Note also that the return statement causes the current function to return immediately. It doesn't just keep going.
– dbush
Dec 27 '18 at 20:29












1 Answer
1






active

oldest

votes


















0














When you do this:



pthread_create(&th1, NULL, tache1, NULL); 
pthread_join(th1, (void*) &sum);

pthread_create(&th2, NULL, tache2, &sum);
pthread_join(th2, (void*) &moyenne);


You start a thread, wait for it to finish, then start another thread, then wait for that to finish. That's not multithreading. You want both threads to be active at the same time.



Also, both of your thread functions include a return statement with more statements after them. Once a return statement is hit, the entire function returns immediately. No statements after them are executed. Note also that you don't need a while (1) (or while (3)) loop in either of these functions.



The idea behind semaphores (and mutexes) is that multiple threads are running at once, and both thread need to operate on global data so one thread needs to wait for the other thread to do something before it can access the global data.



So make sum and moyenne global variables, start both threads at once, and get rid of the extra loops in the thread functions.



#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <semaphore.h>

sem_t evt;
int sum;
int moyenne;

void *tache1(void *arg)
{
int j;
int s=0;

printf("first THREADDDDDDDDD n");

for(j=0; j<100; j++)
s= s + j;

sum = s;
sem_post(&evt);

return NULL;
}


void *tache2(void *arg)
{
sem_wait(&evt);

printf("second THREADDDDDDDDD n");
moyenne= sum/10;

return NULL;
}

int main()
{
pthread_t th1, th2;

sem_init(&evt, 0,0);
printf("start mainn") ;

pthread_create(&th1, NULL, tache1, NULL);
pthread_create(&th2, NULL, tache2, NULL);

pthread_join(th1, NULL);
pthread_join(th2, NULL);

printf("the sum in the main is %d.n", sum);
printf("AVG %d.n", moyenne);
printf("End mainn") ;

return 0;
}





share|improve this answer





















  • Thank you very much for your answer .. the question that I have now is why remove the while ?? according to my knowledge the real time system , the tasks must be periodics so while in my code is for the periodicity ... can you explain to me this point please !!
    – ikram
    Dec 28 '18 at 11:31










  • How can I perform the treatment (sum and avg) using two real-time tasks ??
    – ikram
    Dec 28 '18 at 11:41










  • @ikram You code only calculates the sum and average once, so the threads only need to run once, so no while loops needed.
    – dbush
    Dec 28 '18 at 12:21











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53950305%2freal-time-task-periodic-task%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














When you do this:



pthread_create(&th1, NULL, tache1, NULL); 
pthread_join(th1, (void*) &sum);

pthread_create(&th2, NULL, tache2, &sum);
pthread_join(th2, (void*) &moyenne);


You start a thread, wait for it to finish, then start another thread, then wait for that to finish. That's not multithreading. You want both threads to be active at the same time.



Also, both of your thread functions include a return statement with more statements after them. Once a return statement is hit, the entire function returns immediately. No statements after them are executed. Note also that you don't need a while (1) (or while (3)) loop in either of these functions.



The idea behind semaphores (and mutexes) is that multiple threads are running at once, and both thread need to operate on global data so one thread needs to wait for the other thread to do something before it can access the global data.



So make sum and moyenne global variables, start both threads at once, and get rid of the extra loops in the thread functions.



#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <semaphore.h>

sem_t evt;
int sum;
int moyenne;

void *tache1(void *arg)
{
int j;
int s=0;

printf("first THREADDDDDDDDD n");

for(j=0; j<100; j++)
s= s + j;

sum = s;
sem_post(&evt);

return NULL;
}


void *tache2(void *arg)
{
sem_wait(&evt);

printf("second THREADDDDDDDDD n");
moyenne= sum/10;

return NULL;
}

int main()
{
pthread_t th1, th2;

sem_init(&evt, 0,0);
printf("start mainn") ;

pthread_create(&th1, NULL, tache1, NULL);
pthread_create(&th2, NULL, tache2, NULL);

pthread_join(th1, NULL);
pthread_join(th2, NULL);

printf("the sum in the main is %d.n", sum);
printf("AVG %d.n", moyenne);
printf("End mainn") ;

return 0;
}





share|improve this answer





















  • Thank you very much for your answer .. the question that I have now is why remove the while ?? according to my knowledge the real time system , the tasks must be periodics so while in my code is for the periodicity ... can you explain to me this point please !!
    – ikram
    Dec 28 '18 at 11:31










  • How can I perform the treatment (sum and avg) using two real-time tasks ??
    – ikram
    Dec 28 '18 at 11:41










  • @ikram You code only calculates the sum and average once, so the threads only need to run once, so no while loops needed.
    – dbush
    Dec 28 '18 at 12:21
















0














When you do this:



pthread_create(&th1, NULL, tache1, NULL); 
pthread_join(th1, (void*) &sum);

pthread_create(&th2, NULL, tache2, &sum);
pthread_join(th2, (void*) &moyenne);


You start a thread, wait for it to finish, then start another thread, then wait for that to finish. That's not multithreading. You want both threads to be active at the same time.



Also, both of your thread functions include a return statement with more statements after them. Once a return statement is hit, the entire function returns immediately. No statements after them are executed. Note also that you don't need a while (1) (or while (3)) loop in either of these functions.



The idea behind semaphores (and mutexes) is that multiple threads are running at once, and both thread need to operate on global data so one thread needs to wait for the other thread to do something before it can access the global data.



So make sum and moyenne global variables, start both threads at once, and get rid of the extra loops in the thread functions.



#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <semaphore.h>

sem_t evt;
int sum;
int moyenne;

void *tache1(void *arg)
{
int j;
int s=0;

printf("first THREADDDDDDDDD n");

for(j=0; j<100; j++)
s= s + j;

sum = s;
sem_post(&evt);

return NULL;
}


void *tache2(void *arg)
{
sem_wait(&evt);

printf("second THREADDDDDDDDD n");
moyenne= sum/10;

return NULL;
}

int main()
{
pthread_t th1, th2;

sem_init(&evt, 0,0);
printf("start mainn") ;

pthread_create(&th1, NULL, tache1, NULL);
pthread_create(&th2, NULL, tache2, NULL);

pthread_join(th1, NULL);
pthread_join(th2, NULL);

printf("the sum in the main is %d.n", sum);
printf("AVG %d.n", moyenne);
printf("End mainn") ;

return 0;
}





share|improve this answer





















  • Thank you very much for your answer .. the question that I have now is why remove the while ?? according to my knowledge the real time system , the tasks must be periodics so while in my code is for the periodicity ... can you explain to me this point please !!
    – ikram
    Dec 28 '18 at 11:31










  • How can I perform the treatment (sum and avg) using two real-time tasks ??
    – ikram
    Dec 28 '18 at 11:41










  • @ikram You code only calculates the sum and average once, so the threads only need to run once, so no while loops needed.
    – dbush
    Dec 28 '18 at 12:21














0












0








0






When you do this:



pthread_create(&th1, NULL, tache1, NULL); 
pthread_join(th1, (void*) &sum);

pthread_create(&th2, NULL, tache2, &sum);
pthread_join(th2, (void*) &moyenne);


You start a thread, wait for it to finish, then start another thread, then wait for that to finish. That's not multithreading. You want both threads to be active at the same time.



Also, both of your thread functions include a return statement with more statements after them. Once a return statement is hit, the entire function returns immediately. No statements after them are executed. Note also that you don't need a while (1) (or while (3)) loop in either of these functions.



The idea behind semaphores (and mutexes) is that multiple threads are running at once, and both thread need to operate on global data so one thread needs to wait for the other thread to do something before it can access the global data.



So make sum and moyenne global variables, start both threads at once, and get rid of the extra loops in the thread functions.



#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <semaphore.h>

sem_t evt;
int sum;
int moyenne;

void *tache1(void *arg)
{
int j;
int s=0;

printf("first THREADDDDDDDDD n");

for(j=0; j<100; j++)
s= s + j;

sum = s;
sem_post(&evt);

return NULL;
}


void *tache2(void *arg)
{
sem_wait(&evt);

printf("second THREADDDDDDDDD n");
moyenne= sum/10;

return NULL;
}

int main()
{
pthread_t th1, th2;

sem_init(&evt, 0,0);
printf("start mainn") ;

pthread_create(&th1, NULL, tache1, NULL);
pthread_create(&th2, NULL, tache2, NULL);

pthread_join(th1, NULL);
pthread_join(th2, NULL);

printf("the sum in the main is %d.n", sum);
printf("AVG %d.n", moyenne);
printf("End mainn") ;

return 0;
}





share|improve this answer












When you do this:



pthread_create(&th1, NULL, tache1, NULL); 
pthread_join(th1, (void*) &sum);

pthread_create(&th2, NULL, tache2, &sum);
pthread_join(th2, (void*) &moyenne);


You start a thread, wait for it to finish, then start another thread, then wait for that to finish. That's not multithreading. You want both threads to be active at the same time.



Also, both of your thread functions include a return statement with more statements after them. Once a return statement is hit, the entire function returns immediately. No statements after them are executed. Note also that you don't need a while (1) (or while (3)) loop in either of these functions.



The idea behind semaphores (and mutexes) is that multiple threads are running at once, and both thread need to operate on global data so one thread needs to wait for the other thread to do something before it can access the global data.



So make sum and moyenne global variables, start both threads at once, and get rid of the extra loops in the thread functions.



#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <semaphore.h>

sem_t evt;
int sum;
int moyenne;

void *tache1(void *arg)
{
int j;
int s=0;

printf("first THREADDDDDDDDD n");

for(j=0; j<100; j++)
s= s + j;

sum = s;
sem_post(&evt);

return NULL;
}


void *tache2(void *arg)
{
sem_wait(&evt);

printf("second THREADDDDDDDDD n");
moyenne= sum/10;

return NULL;
}

int main()
{
pthread_t th1, th2;

sem_init(&evt, 0,0);
printf("start mainn") ;

pthread_create(&th1, NULL, tache1, NULL);
pthread_create(&th2, NULL, tache2, NULL);

pthread_join(th1, NULL);
pthread_join(th2, NULL);

printf("the sum in the main is %d.n", sum);
printf("AVG %d.n", moyenne);
printf("End mainn") ;

return 0;
}






share|improve this answer












share|improve this answer



share|improve this answer










answered Dec 27 '18 at 21:16









dbush

93.1k12101134




93.1k12101134












  • Thank you very much for your answer .. the question that I have now is why remove the while ?? according to my knowledge the real time system , the tasks must be periodics so while in my code is for the periodicity ... can you explain to me this point please !!
    – ikram
    Dec 28 '18 at 11:31










  • How can I perform the treatment (sum and avg) using two real-time tasks ??
    – ikram
    Dec 28 '18 at 11:41










  • @ikram You code only calculates the sum and average once, so the threads only need to run once, so no while loops needed.
    – dbush
    Dec 28 '18 at 12:21


















  • Thank you very much for your answer .. the question that I have now is why remove the while ?? according to my knowledge the real time system , the tasks must be periodics so while in my code is for the periodicity ... can you explain to me this point please !!
    – ikram
    Dec 28 '18 at 11:31










  • How can I perform the treatment (sum and avg) using two real-time tasks ??
    – ikram
    Dec 28 '18 at 11:41










  • @ikram You code only calculates the sum and average once, so the threads only need to run once, so no while loops needed.
    – dbush
    Dec 28 '18 at 12:21
















Thank you very much for your answer .. the question that I have now is why remove the while ?? according to my knowledge the real time system , the tasks must be periodics so while in my code is for the periodicity ... can you explain to me this point please !!
– ikram
Dec 28 '18 at 11:31




Thank you very much for your answer .. the question that I have now is why remove the while ?? according to my knowledge the real time system , the tasks must be periodics so while in my code is for the periodicity ... can you explain to me this point please !!
– ikram
Dec 28 '18 at 11:31












How can I perform the treatment (sum and avg) using two real-time tasks ??
– ikram
Dec 28 '18 at 11:41




How can I perform the treatment (sum and avg) using two real-time tasks ??
– ikram
Dec 28 '18 at 11:41












@ikram You code only calculates the sum and average once, so the threads only need to run once, so no while loops needed.
– dbush
Dec 28 '18 at 12:21




@ikram You code only calculates the sum and average once, so the threads only need to run once, so no while loops needed.
– dbush
Dec 28 '18 at 12:21


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53950305%2freal-time-task-periodic-task%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas