开发者

incrementing value of hour inside a function when current hour change its value

I want to increment myTime(dt1 below) variable when currentHour changes inside a function; I am using RWDatetime.

RWDateTime dt1;

int func()
{
  RWDateTime dt(setCurrentTime());
  //when dt increment by 开发者_Python百科an hour i have to increment dt1 in below section by an hour

}
//One important note i am in multithreaded environment 

Pls suggest a good method i have implemented it by storing values in global static std::set<>... but i want a better approch as its multithreaded environment that why this is not right approch.


RWDateTime::incrementHour

Usage:

RWDateTime dt1;

int func()
{
  RWDateTime dt(setCurrentTime());
  //when dt increment by an hour i have to increment dt1 in below section by an hour
  unsigned h = dt.hour();

  ...

    if(h != dt.hour())
      dt.incrementHour(1);

}


lock the access to dt1 with a semaphore. lock the write, and the 'critical' sections that use it.

... Or... by the way couldn't you send that data, usefull for computation for various threads, along in an argument of your function func() ? it would seem a more reliable design, bu obviously i don t have all informations to be able to tell for your problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜