|
|
Home » Developing U++ » UppHub » Job package: A lightweight worker thread for non-blocking operations. (A)
Re: RE: Job package: A scope-bound worker thread for non-blocking operations. [message #48829 is a reply to message #48796] |
Sat, 07 October 2017 15:03   |
Oblivion
Messages: 1209 Registered: August 2007
|
Senior Contributor |
|
|
Hello,
Job package is now compatible with single-threaded U++ environment. (Yet -almost- all methods and global functions retain their functionality under ST env.)
Documentation and provided example is updated accordingly.
The code below is a part of JobExample.cpp and demonstrates both non-blocking behaviour and Job cancelling feature in a single-threaded environment:
void CancelJob()
{
// Singlethreaded version. (non-blocking operation)
// Below example is one of the simplest ways to achive non-blocking operations with Job in a
// single-threaded environment. A finer-grained operation would involve handling of return
// codes. (e.g. using Job<int>)
Job<void> job;
auto work = [=] {
if(IsJobCancelled()) {
Cout() << "Worker #" << GetWorkerId() << " received cancel signal. Cancelling job...\n";
throw JobError("Operation cancelled.");
}
};
Cout() << "Worker #" << GetWorkerId() << " started. (Waiting the cancellation signal...)\n";
const int timeout = 5000;
auto start_time = msecs();
while(!job.IsError()) {
job.Start(work);
if(msecs(start_time) >= timeout)
job.Cancel(); // Or if you have more than one non-blocking operation in progress,
// you can call CancelJobs() global function to cancel all running jobs.
}
}
As always, reviews, criticism, bug reports, etc. are deeply appreciated.
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: Sat, 07 October 2017 15:09] Report message to a moderator
|
|
|
 |
|
Job package: A lightweight worker thread for non-blocking operations.
By: Oblivion on Sun, 10 September 2017 12:29
|
 |
|
Re: Job package: A lightweight multithreading tool, using promise/future mechanism
By: mirek on Sun, 10 September 2017 15:08
|
 |
|
Re: Job package: A lightweight multithreading tool, using promise/future mechanism
By: mirek on Sun, 10 September 2017 15:56
|
 |
|
Re: Job package: A lightweight multithreading tool, using promise/future mechanism
By: Oblivion on Sun, 10 September 2017 17:05
|
 |
|
Re: Job package: A lightweight multithreading tool, using promise/future mechanism
By: Oblivion on Sun, 10 September 2017 19:08
|
 |
|
Re: Job package: A lightweight multithreading tool, using promise/future mechanism
By: mirek on Sun, 10 September 2017 20:13
|
 |
|
Re: Job package: A lightweight multithreading tool, using promise/future mechanism
By: Oblivion on Sun, 10 September 2017 21:16
|
 |
|
Re: Job package: A lightweight multithreading tool, using promise/future mechanism
By: mirek on Mon, 11 September 2017 00:06
|
 |
|
Re: Job package: A lightweight multithreading tool, using promise/future mechanism
By: Oblivion on Mon, 11 September 2017 00:25
|
 |
|
RE: Job package: A scope-bound worker thread for non-blocking operations.
By: Oblivion on Sun, 17 September 2017 23:20
|
 |
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: mirek on Mon, 18 September 2017 08:23
|
 |
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: Oblivion on Mon, 18 September 2017 08:29
|
 |
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: Oblivion on Tue, 19 September 2017 00:01
|
 |
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: mirek on Tue, 19 September 2017 08:37
|
 |
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: Oblivion on Tue, 19 September 2017 08:53
|
 |
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: mirek on Tue, 19 September 2017 10:12
|
 |
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: Oblivion on Tue, 19 September 2017 08:12
|
 |
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: mirek on Tue, 19 September 2017 10:15
|
 |
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: mirek on Tue, 19 September 2017 10:24
|
 |
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: Oblivion on Tue, 19 September 2017 11:12
|
 |
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: Oblivion on Tue, 19 September 2017 12:31
|
 |
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: mirek on Tue, 19 September 2017 13:01
|
 |
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: Oblivion on Sat, 23 September 2017 14:17
|
 |
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: Oblivion on Sat, 07 October 2017 15:03
|
 |
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: mirek on Sat, 07 October 2017 15:51
|
 |
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: Oblivion on Sat, 07 October 2017 16:04
|
 |
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: Oblivion on Sun, 08 October 2017 15:01
|
 |
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: Oblivion on Tue, 10 October 2017 11:51
|
 |
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: mirek on Tue, 10 October 2017 16:10
|
 |
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: Oblivion on Tue, 10 October 2017 17:02
|
 |
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: mirek on Tue, 10 October 2017 20:51
|
 |
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: Oblivion on Tue, 10 October 2017 23:48
|
 |
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: mirek on Wed, 11 October 2017 09:23
|
 |
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: Oblivion on Wed, 11 October 2017 09:42
|
 |
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: mirek on Wed, 11 October 2017 09:47
|
 |
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: Oblivion on Wed, 11 October 2017 09:50
|
 |
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: mirek on Wed, 11 October 2017 19:30
|
 |
|
Re: RE: Job package: A scope-bound worker thread for non-blocking operations.
By: Oblivion on Wed, 11 October 2017 20:14
|
 |
|
Re: Job package: A lightweight multithreading tool, using promise/future mechanism
By: mirek on Sun, 10 September 2017 20:09
|
Goto Forum:
Current Time: Fri Jun 06 22:03:50 CEST 2025
Total time taken to generate the page: 0.04168 seconds
|
|
|