473,387 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Help me design my scheduler

Anyone know of a reliable design for a Windows C++ Task Scheduler
Class.
The scheduler will expose a member function that will add schedules,
its parameters will be an interval to run the tasks and a function
pointer. This function pointer will be a void* function in other
objects that will use the scheduler.
So when another object calls the addSchedule function the scheduler
will run these tasks at each interval provided. There may be a number
of tasks running at the same time.

Should I design this as single or multi threaded, it seems I need to
make it multi threaded as I may have to use a waitable timer? But would
prefer the debugging ease of a single threaded design.

Should I make the scheduler a singleon?

There is an example quite similar at:
http://www.codeguru.com/Cpp/W-P/syst...cle.php/c5783/

But this example does not work in a Windows Service and when I use a
waitable timer I have to make it multithreaded.

So any ideas\pointers\links for me on a good base design for this
class.

Enda

Oct 6 '05 #1
4 10589
ke****************@yahoo.co.uk wrote:
Anyone know of a reliable design for a Windows C++ Task Scheduler
Class.
The scheduler will expose a member function that will add schedules,
its parameters will be an interval to run the tasks and a function
pointer. This function pointer will be a void* function in other
objects that will use the scheduler.
So when another object calls the addSchedule function the scheduler
will run these tasks at each interval provided. There may be a number
of tasks running at the same time.

Should I design this as single or multi threaded, it seems I need to
make it multi threaded as I may have to use a waitable timer? But would
prefer the debugging ease of a single threaded design.

Should I make the scheduler a singleon?

There is an example quite similar at:
http://www.codeguru.com/Cpp/W-P/syst...cle.php/c5783/

But this example does not work in a Windows Service and when I use a
waitable timer I have to make it multithreaded.

So any ideas\pointers\links for me on a good base design for this
class.

Enda


This newsgroup is for standard C++ language issues, and since the
standard knows nothing of threading, your questions fall outside the
scope of the group. You'll likely get better help in the group you
cross-posted to: comp.os.ms-windows.programmer.win32.

Cheers! --M

Oct 6 '05 #2
Well... there was a reference in my question to a Singleton class and a
general design for my class. Also in designing this class it seems
that it would be quite important to keep threading in mind.

Also thanks for the alternative group.

Anyway I have came up with a soloution and it involves exposing an
addSchedule function when called the first time a thread is created
and the waitable timer is created and setup. Subsequent calls to this
function will not create the thread again or create the timer just
update the timer.

The task is appended to a linked list of tasks that is another object.

When the timer expires the function is run.

Enda

Oct 6 '05 #3
ke****************@yahoo.co.uk wrote:
Well... there was a reference in my question to a Singleton class and a
general design for my class. Also in designing this class it seems
that it would be quite important to keep threading in mind.

[snip]

As to the singleton, that's technically not a C++ language question
either. (Implementation is another story -- see _Modern C++ Design_ for
more than you ever wanted to know about implementing singletons.) In
any case, making the scheduler a singleton obviously depends on whether
you can have more than one instance of it. If there can by definition
only be one in your application, then a singleton seems like a good
idea. If you will have multiple schedulers to handle different sets of
tasks or whatever, then obviously you shouldn't make it a singleton. We
don't really know enough about your application to provide direct
advice on that front.

If by "tasks" you mean other processes on the windows machine, then
making it a singleton probably doesn't matter because you're providing
access to the scheduler through COM or some other such interface.
(You'll need to decide if there can be more than one instance of the
scheduler process running, but that's not a singleton in the C++ sense
and is well outside the scope of this NG.)

Cheers! --M

Oct 6 '05 #4
ke****************@yahoo.co.uk wrote:
Anyone know of a reliable design for a Windows C++ Task Scheduler
Class.
It is very unfortunate, but the C++ language specification does not mention
threads at all. Not only puts that multi-threading somewhat out of the
scope of this news group, but it also makes it close to impossible to argue
the correctness of a multi-threaded C++ program. If you want to know about
the particular API and guarantees of certain threading libraries, your best
bet would be a newsgroup for your platform.

Some basic threading support is also offered in boost, if I recall
correctly.

The scheduler will expose a member function that will add schedules,
its parameters will be an interval to run the tasks and a function
pointer. This function pointer will be a void* function in other
objects that will use the scheduler.
So when another object calls the addSchedule function the scheduler
will run these tasks at each interval provided. There may be a number
of tasks running at the same time.

Should I design this as single or multi threaded, it seems I need to
make it multi threaded as I may have to use a waitable timer? But would
prefer the debugging ease of a single threaded design.

Should I make the scheduler a singleon?


I do not see a reason for that. If I understand you correctly, the program
could register a function pointer with a scheduler and create a thread that
way. I consider it perfectly feasible to create another scheduler, say
within a given thread, and recursively register sub-threads with the local
scheduler object. This kind of recursive scheduling strategy is actually
used every once in a while. So why preclude it by design of the scheduler
class?

There is nothing inherently unique about a scheduler object. If your
application, by conincidence, does not need more than one scheduler, just
do not create another scheduler object. [This is very similar to clocks:
most programs happen to use at most one, but there is nothing inherently
unique about clocks, so I do not see any reasons to make a Clock class a
singleton.]
Best

Kai-Uwe Bux
Oct 6 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Rookie | last post by:
I need to display several columns of numbers in a textbox. I wish to display the columns with the decimal point position aligned vertically. I have found that the # digit placeholders do not...
3
by: fernandez.dan | last post by:
I'm still learning how to use Object Oriented concepts. I'm have a basic question dealing with design. I have two classes that deal with I/O pertaining to network and usb that inherit from an...
0
by: Mobile Boy 36 | last post by:
I'm trying to make a very simple Textbox with a FocusColor property...When the focus changes to the control, the backcolor must change automaticly to the color set by the focusColor property....
3
by: Darren | last post by:
I have a Person object and from that I'm inheriting other objects including Client, Carer, Doctor (and others). The Person object has a large number of properties and methods that I want available...
8
by: cmay | last post by:
I am looking for something to help me with documenting / planning / designing my asp.net applications. Once in a while I try doing some UML in Visio, but it really feels like overkill, espically...
2
by: news.microsoft.com | last post by:
I need help design a reg exp. I am parsing an html file to get the input values, here is one example <input VALUE="Staff Writer" size=60 type="text" name="author"> Can I grab the value "Staff...
0
by: neioxp | last post by:
Hi, I am now in a client engagement project for a Smart Client application. As we all know that one of the greatest factors why Smart Client Architecture is on the hip otherwise known as the...
2
by: yamca | last post by:
I want to write a task scheduler. But i cant make the logic between the scheduler and tasks. For example a have an external process which can add and delete tasks from scheduler. Every task has...
12
by: enwriter | last post by:
I'm a member of a social network and I would like to expand the margins in the template I have. There is a HTML reader to help design your page. Please tell me the code for expanding the...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.