473,396 Members | 2,061 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,396 software developers and data experts.

how to restart a thread?

Hi, I'm writing a background timer using /cc++/thread.h.
this is my source code:

timer.h
-----------------------------------------------
#ifndef TIMER_H
#define TIMER_H
#include <cc++/thread.h>

using namespace std;
using namespace ost;

class Timer : public Thread
{
private:
int timeout;
public:
Timer();
~Timer();
void setTimer(float t);
void run();
};

#endif

timer.cpp
-------------------------------------
#include "timer.h"
#include <iostream>

Timer::Timer()
{

}

Timer::~Timer()
{
terminate();

}

void Timer::setTimer(float t)
{
timeout = (int)(t * 1000);

}

void Timer::run()
{
sleep(timeout);
exit();

}

I use my timer in this way:

Timer *t1 = new Timer();
float oldTimeout = 3;
t1->setTimer(oldTimeout);
t1->detach();

and then I want to restart it when expired:

oldTimeout = 2*oldTimeout;
t1->setTimer(oldTimeout);
int i = t1->detach();

but i == -1 (error) and timer does not start again.

what's wrong?

Feb 23 '07 #1
1 8337
On Feb 23, 9:56 am, "fabiosc...@gmail.com" <fabiosc...@gmail.com>
wrote:
Hi, I'm writing a background timer using /cc++/thread.h.
this is my source code:

timer.h
-----------------------------------------------
#ifndef TIMER_H
#define TIMER_H
#include <cc++/thread.h>

using namespace std;
using namespace ost;

class Timer : public Thread
{
private:
int timeout;
public:
Timer();
~Timer();
void setTimer(float t);
void run();

};

#endif

timer.cpp
-------------------------------------
#include "timer.h"
#include <iostream>

Timer::Timer()
{

}

Timer::~Timer()
{
terminate();

}

void Timer::setTimer(float t)
{
timeout = (int)(t * 1000);

}

void Timer::run()
{
sleep(timeout);
exit();

}

I use my timer in this way:

Timer *t1 = new Timer();
float oldTimeout = 3;
t1->setTimer(oldTimeout);
t1->detach();

and then I want to restart it when expired:

oldTimeout = 2*oldTimeout;
t1->setTimer(oldTimeout);
int i = t1->detach();

but i == -1 (error) and timer does not start again.

what's wrong?
We have no idea. Threads are not part of standard C++, and we don't
know anything about your thread library. Ask in a group that deals
with threads (e.g., comp.programming.threads) or in a forum for your
thread library. See:

http://www.parashift.com/c++-faq-lit...t.html#faq-5.9

Cheers! --M

Feb 23 '07 #2

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

Similar topics

3
by: Kranthis | last post by:
Hi, I want to restart a thread after same variable value in the thread reaches 100 in c# . How can I do. Please suggest me any solution
1
by: localhost | last post by:
In the Application_OnStart, I make some data calls and place the results in the HTTP cache. Sometimes, the database is not available when the application starts up, so I want to sleep for 20...
2
by: Chris Langston | last post by:
I have a Web Server running IIS 5 or 6 on Windows 2K and Windows 2003 Server that is experiencing strange shutdown problems. We are using ASP.NET v1.1 and our application is written in VB.NET ...
14
by: iceman | last post by:
Hello, I have a windows service. I want to restart it after every 24 hour. Is it possible to restart the service programmatically(from the service itself) using the sercvice controller object?...
6
by: Leonardo Curros | last post by:
Hello, I would like to know what's the best way to restart one service. I would like to do it from the service itself. Is this possible? I try it with ServiceController.stop()...
1
by: Mamatha | last post by:
Hi I have one doubt regarding threads in my application. If i aborted one thread ,then i want to restart the same thread again.How can i restart that one. Is it possible to restart a thred...
22
by: Brett | last post by:
I have a second thread, t2, that errors out and will stop. It's status is then "Stopped". I try to start t2 from thread 1, t1, by checking If t2.threadstate = "Stopped" Then t2.start() ...
5
by: juky | last post by:
Hi all, I have 3 running threads chencking for something in my application. Based on that I need to stop some of them safely wait for something else and restart. Sleep is not good in my case...
1
by: many_years_after | last post by:
class mythread(threading.Thread): def __init__(self, threadname): threading.Thread.__init__(self, name = threadname) def run(self): print 'i am running' print 'i quit run()' thread =...
5
by: David Thielen | last post by:
Hi; We keep having to restart IIS after ASP.NET kills it. Below is what we have in the event log. Any idea what the problem is? thanks - dave Event code: 3003 Event message: A validation...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.