I want to do a timed join, with a relative time of 0.1s. I can not figure out from the docs how to do this. I find the prototypes somewhat mystifying: bool timed_join(const system_time& wait_until); template<typename TimeDuration> bool timed_join(TimeDuration const& rel_time); What is system_time? What should TimeDuration be? I'm using Windows. Thank you, Johan Råde
Johan Råde wrote:
I want to do a timed join, with a relative time of 0.1s. I can not figure out from the docs how to do this. I find the prototypes somewhat mystifying:
bool timed_join(const system_time& wait_until);
template<typename TimeDuration> bool timed_join(TimeDuration const& rel_time);
What is system_time? What should TimeDuration be?
I'm using Windows.
Thank you, Johan Råde
I figured out the answer myself: int n = (int)boost::posix_time::time_duration::ticks_per_second() / 10; boost::posix_time::time_duration delay(0,0,0,n); thr.timed_join(delay); I bit more complex than I had expected. --Johan
Not tested but there must be other ways of doing it like: Typedef Btime = boost::posix_time; Typedef Bperiod = Btime::time_duration; thr.timed_join(Bperiod (0,0,0, Btime::millisec( 100 ) ) ); perhaps even thr.timed_join(Btime::millisec( 100 ) ); or thr.timed_join(Bperiod (0,0,0, 100 ) ); As this is a cross platform library ticks_per_second should not be required. -----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Johan Råde Sent: 17 April 2008 11:47 To: boost-users@lists.boost.org Subject: Re: [Boost-users] [thread] how to use thread::timed_join Johan Råde wrote:
I want to do a timed join, with a relative time of 0.1s. I can not figure out from the docs how to do this. I find the prototypes somewhat mystifying:
bool timed_join(const system_time& wait_until);
template<typename TimeDuration> bool timed_join(TimeDuration const& rel_time);
What is system_time? What should TimeDuration be?
I'm using Windows.
Thank you, Johan Råde
I figured out the answer myself: int n = (int)boost::posix_time::time_duration::ticks_per_second() / 10; boost::posix_time::time_duration delay(0,0,0,n); thr.timed_join(delay); I bit more complex than I had expected. --Johan _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users ______________________________________________________________________ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email ______________________________________________________________________ ****************************************************************************** "This message and any attachments are solely for the intended recipient and may contain confidential and privileged information. If you are not the intended recipient, any disclosure, copying, use, or distribution of the information included in this message and any attachments is prohibited. If you have received this communication in error, please notify us by reply e-mail and immediately and permanently delete this message and any attachments. Thank you." Interactive Transaction Solutions Ltd (2473364 England) Registered Office: Systems House, Station Approach Emsworth PO10 7PW ********************************************************************** Ce message électronique contient des informations confidentielles à l'usage unique des destinataires indiqués, personnes physiques ou morales. Si vous n'êtes pas le destinataire voulu, toute divulgation, copie, ou diffusion ou toute autre utilisation de ces informations, est interdite. Si vous avez reçu ce message électronique par erreur, nous vous remercions d'en avertir son expéditeur immédiatement par email et de détruire ce message ainsi que les éléments attachés. Interactive transaction Solutions SAS- France (RCS Pontoise : 489 397 877) Siège social : Parc Saint Christophe, 10, Avenue de lEntreprise 95865 Cergy-Pontoise Cedex ______________________________________________________________________ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email ______________________________________________________________________
Johan Råde
I want to do a timed join, with a relative time of 0.1s. I can not figure out from the docs how to do this. I find the prototypes somewhat mystifying:
bool timed_join(const system_time& wait_until);
template<typename TimeDuration> bool timed_join(TimeDuration const& rel_time);
What is system_time? What should TimeDuration be?
system_time is declared in boost/thread/thread_time.hpp: it is a typedef to boost::posix_time::ptime from the date-time library. TimeDuration is any boost date-time duration. e.g. boost::posix_time::milliseconds You are not the only person to notice the missing docs for the timeout stuff. It's on my list of things to add. Anthony -- Anthony Williams | Just Software Solutions Ltd Custom Software Development | http://www.justsoftwaresolutions.co.uk Registered in England, Company Number 5478976. Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL
On Sun, Apr 20, 2008 at 12:49 AM, Anthony Williams
Johan Råde
writes: I want to do a timed join, with a relative time of 0.1s. I can not figure out from the docs how to do this. I find the prototypes somewhat mystifying:
bool timed_join(const system_time& wait_until);
template<typename TimeDuration> bool timed_join(TimeDuration const& rel_time);
What is system_time? What should TimeDuration be?
system_time is declared in boost/thread/thread_time.hpp: it is a typedef to boost::posix_time::ptime from the date-time library.
TimeDuration is any boost date-time duration. e.g. boost::posix_time::milliseconds
You are not the only person to notice the missing docs for the timeout stuff. It's on my list of things to add.
There's some examples of how to construct these types on the boost date-time docs: http://www.boost.org/doc/libs/1_35_0/doc/html/date_time/posix_time.html#date... You can use time_duration, but really the easy way is to construct from the 'count types'": milliseconds, nanoseconds, etc. Jeff
Jeff Garland wrote:
On Sun, Apr 20, 2008 at 12:49 AM, Anthony Williams
mailto:anthony_w.geo@yahoo.com> wrote: Johan Råde
mailto:rade@maths.lth.se> writes: > I want to do a timed join, with a relative time of 0.1s. > I can not figure out from the docs how to do this. > I find the prototypes somewhat mystifying: > > bool timed_join(const system_time& wait_until); > > template<typename TimeDuration> bool timed_join(TimeDuration const& rel_time); > > What is system_time? > What should TimeDuration be?
system_time is declared in boost/thread/thread_time.hpp: it is a typedef to boost::posix_time::ptime from the date-time library.
TimeDuration is any boost date-time duration. e.g. boost::posix_time::milliseconds
You are not the only person to notice the missing docs for the timeout stuff. It's on my list of things to add.
There's some examples of how to construct these types on the boost date-time docs:
http://www.boost.org/doc/libs/1_35_0/doc/html/date_time/posix_time.html#date...
You can use time_duration, but really the easy way is to construct from the 'count types'": milliseconds, nanoseconds, etc.
Jeff
Thanks for the help. I had never used the Boost.DateTime library before and hadn't realized that the Boost.Thread library interface depends on the Boost.DateTime library. Boost.DateTime looks like an excellent library. I will make more use of it in the future. A minor annoyance with Boost.DateTime: boost::posix_time::milliseconds is a bit too verbose for my taste, while just milliseconds is too brief. posix_time::milliseconds seems just right. If posix_time had been a class, then you could have written using boost::posix_time; ... posix_time::milliseconds ... But since posix_time is a name space that can not be achieved. Is there any way in C++ of bringing the name of namespace into the global scope without bringing every name inside the namespace into the global scope? --Johan
------------------------------------------------------------------------
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
If posix_time had been a class, then you could have written> > using boost::posix_time;> > ... posix_time::milliseconds ...> > But since posix_time is a name space that can not be achieved.> > Is there any way in C++ of bringing the name of namespace into the global scope> without bringing every name inside the namespace into the global scope?> > --Johan
Your last question contains kindof contradiction :). Anyway, you can do something like this: namepspace pt = boost::posix_time; pt::milliseconds ... _________________________________________________________________ Invite your mail contacts to join your friends list with Windows Live Spaces. It's easy! http://spaces.live.com/spacesapi.aspx?wx_action=create&wx_url=/friends.aspx&mkt=en-us
On Mon, Apr 21, 2008 at 8:29 AM, Johan Råde
Thanks for the help. I had never used the Boost.DateTime library before and hadn't realized that the Boost.Thread library interface depends on the Boost.DateTime library.
Just to clarify, the thread library hasn't used the date-time types up till 1.35 -- it's something that's been long discussed, it just took a long time to get to. Also, this type of interface has now been proposed for C++0x -- unfortunately it's been somewhat controversial so it's been, in and now out, of the working draft. Jeff
participants (5)
-
Anthony Williams
-
Igor R.
-
Jeff Garland
-
Johan Råde
-
Patrick Loney