Re: [Boost-users] [Threads] How to keep number of running thread constant, performing different operations

I've tryed implementing your suggestions with the following code:
#include <iostream>
#include
#include
#include
#include
#include
void handler1()
{
unsigned short int i;
std::cout << "O--> Handler 1 <--O" << std::endl;
for(i=0; i<65000; i++);
std::cout << "X--> Handler 1 <--X" << std::endl;
}
void handler2()
{
unsigned short int i;
std::cout << "O--> Handler 2 <--O" << std::endl;
for(i=0; i<1000; i++);
std::cout << "X--> Handler 2 <--X" << std::endl;
}
int main()
{
unsigned short nProc,
i;
boost::asio::io_service io;
boost::scoped_ptrboost::asio::io_service::work work(new
boost::asio::io_service::work(io));
boost::thread_group tg;
nProc = boost::thread::hardware_concurrency();
for(i=0; i

"unsigned short int i;" - is 16bit variable.
see here: http://liveworkspace.org/code/b88123920e184955e61aee9cc0c217c6
i.e. in your code variable "i" is overflowed.
2011/9/1 Alessandro Candini

On Thu, Sep 01, 2011 at 04:33:12PM +0400, niXman wrote:
I object to this statement. unsigned short is not necessarily 16-bit.
It's inbetween char and int in size, possibly the same as either of
them.
Citing any implementation as a source of definitive sizes is flawed.
On his particular platform, it seems to be 16 bits in size, but it sure
doesn't hold in general.
If you want a 16-bit unsigned integral type, use uint16_t from <cstdint>
or
participants (3)
-
Alessandro Candini
-
Lars Viklund
-
niXman