Home » U++ Library support » U++ MT-multithreading and servers » AsyncWork, IsFinished() may not be working properly
AsyncWork, IsFinished() may not be working properly [message #49671] |
Wed, 28 March 2018 19:17 |
Oblivion
Messages: 1091 Registered: August 2007
|
Senior Contributor |
|
|
Hello,
Either I am doing something wrong, or AsyncWork/CoWork's IsFinished() method is not working properly (Tested on latest Upp/GCC/Linux kernel).
It always returns true;
Here is a simple test code to show the problem:
#include <Core/Core.h>
using namespace Upp;
CONSOLE_APP_MAIN
{
StdLogSetup(LOG_FILE|LOG_COUT);
Array<AsyncWork<void>> workers;
for(int i = 0; i < 4; i++) {
workers.Add() = Async([=]{ LOG("Started, worker #" << i); for(;;); });
}
Sleep(5000);
// while(!workers.IsEmpty())
for(int i = 0; i < workers.GetCount(); i++) {
auto& w = workers[i];
if(w.IsFinished())
LOG("Stopped, worker #" << i); // <<- Called, when it shouldn't.
}
}
In the above test code, workers are supposed to run forever. So IsFinished should (?) return false. But when I check them with IsFinished() method, I get positive results every time.
Am I doing something wrong?
Here is the log:
CoWork constructed 7f86caf82060
Do0, looper: false, previous todo: 0
Pool::InitThreads: 8
CoWork thread #0 started
CoWork thread #1 started
CoWork thread #2 started
CoWork thread #3 started
CoWork thread #4 started
CoWork thread #5 started
CoWork thread #6 started
CoWork thread #7 started
#1 Waiting for job
Adding job
Releasing thread waiting for job, waiting threads: 1
#1 Waiting ended
#1 Job acquired
DoJob (CoWork 7f86caf82060)
Started worker #0
#4 Waiting for job
CoWork constructed 7f86caf82140
Do0, looper: false, previous todo: 0
#5 Waiting for job
#0 Waiting for job
#3 Waiting for job
#6 Waiting for job
#7 Waiting for job
#2 Waiting for job
Adding job
Releasing thread waiting for job, waiting threads: 7
CoWork constructed 7f86caf82220
Do0, looper: false, previous todo: 0
#4 Waiting ended
#4 Job acquired
DoJob (CoWork 7f86caf82140)
Started worker #1
Adding job
Releasing thread waiting for job, waiting threads: 6
CoWork constructed 7f86caf82300
Do0, looper: false, previous todo: 0
Adding job
Releasing thread waiting for job, waiting threads: 6
#0 Waiting ended
#0 Job acquired
DoJob (CoWork 7f86caf82300)
Started worker #3
#5 Waiting ended
#5 Job acquired
DoJob (CoWork 7f86caf82220)
Started worker #2
Stopped worker #0
Stopped worker #1
Stopped worker #2
Stopped worker #3
CoWork Cancel0
WaitForFinish (CoWork 7f86caf82060)
//...
Best regards,
Oblivion
Github page: https://github.com/ismail-yilmaz
upp-components: https://github.com/ismail-yilmaz/upp-components
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Wed, 28 March 2018 19:17] Report message to a moderator
|
|
|
|
|
AsyncWork, IsFinished() may not be working properly
By: Oblivion on Wed, 28 March 2018 19:17
|
|
|
Re: AsyncWork, IsFinished() may not be working properly
By: mirek on Sat, 31 March 2018 07:49
|
|
|
Re: AsyncWork, IsFinished() may not be working properly
By: Oblivion on Sat, 31 March 2018 12:51
|
|
|
Re: AsyncWork, IsFinished() may not be working properly
By: JeyCi on Fri, 17 July 2020 12:48
|
|
|
Re: AsyncWork, IsFinished() may not be working properly
By: JeyCi on Sat, 18 July 2020 07:51
|
|
|
Re: AsyncWork, IsFinished() may not be working properly
|
|
|
Re: AsyncWork, IsFinished() may not be working properly
By: JeyCi on Sat, 18 July 2020 14:21
|
|
|
Re: AsyncWork, IsFinished() may not be working properly
|
|
|
Re: AsyncWork, IsFinished() may not be working properly
By: JeyCi on Sat, 18 July 2020 16:44
|
|
|
Re: AsyncWork, IsFinished() may not be working properly
By: JeyCi on Sat, 18 July 2020 17:06
|
|
|
Re: AsyncWork, IsFinished() may not be working properly
|
|
|
Re: AsyncWork, IsFinished() may not be working properly
By: JeyCi on Sat, 18 July 2020 18:34
|
|
|
Re: AsyncWork, IsFinished() may not be working properly
|
|
|
Re: AsyncWork, IsFinished() may not be working properly
By: JeyCi on Sat, 18 July 2020 21:02
|
Goto Forum:
Current Time: Thu Mar 28 13:11:44 CET 2024
Total time taken to generate the page: 0.01444 seconds
|