In my project for some reason I am creating my thread in suspended state and after some state I am resuming the thread. So when resuming the thread sometime it might work or sometime it is not. So what is the proper way of handling the error if doesn't work?? Should I retry for resuming the thread or should I wait for some time or any possible appropriate handling mechanism?? Please guide me the best way of handling the scenarios. I am using ACE thread library here.
Asked
Active
Viewed 78 times
0
-
Why doesn't the thread work? With what error does it return? – RedX Jan 14 '14 at 13:49
-
It doesn't work sometime. It returns the status 0. – Chris Jan 14 '14 at 13:56
-
1`It doesn't work` is not enough. Maybe you can provide the code it should execute. Maybe you can try returning different error codes to show the progress in the thread. How are you starting your thread? – RedX Jan 14 '14 at 13:58
-
Specifically, you need to specify what "It doesn't work" means, does the thread not start, or does the thread run but fails to do something (such as open a file that doesn't exist), or does the thread cause an exception (either C++ or a hardware exception)? These are very different things. – Damon Jan 14 '14 at 16:39
-
1Suspending and resuming threads is dangerous, a thread should block when it has nothing to do (by taking a semaphore for example), and should be unblocked with some kind of notification like another thread giving the semaphore. – Chris Desjardins Jan 14 '14 at 16:54
-
sorry...when I am trying to resume the thread, it doesn't start. – Chris Jan 14 '14 at 18:59
1 Answers
0
May I suggest a message queue? A simple implementation would just be an std::vector
of updates, where each value in the vector represents an update like loading an asset (whose update architecture would include success/error code and filename) or letting another thread know that a key has been pressed/released.
EDIT:
As Damon said, you also need a mutex so only one thread at a time is editing the message queue.
-
Message queue is generally a good suggestion with "thread" in mind, even if the actual problem that the OP is having isn't yet known. But you should add "and a mutex" to your suggestion of using "just" a `std::vector` (I would personally rather use a ringbuffer, too - `vector` isn't really great for that purpose). – Damon Jan 14 '14 at 16:42
-
@Damon Yes, totally forgot about a [mutex](http://stackoverflow.com/a/34558/3151642)... – Proxy Jan 14 '14 at 18:53