I am on C2D (Core 2 Duo Intel) and your code is working fine on my machine; all threads started and both core had used;

I make a little change; I renamed your class from "shared_mutex" to "shared_mutex1" and same for constructors and destructors.

I was getting redefination of that class. After changing name; every thing is working fine.


-Rahul
 
To create something exceptional

-Master4Master
"Confidentiality Warning: This message and any attachments are intended only for the use of the intended recipient(s), are confidential, and may be privileged. If you are not the intended recipient, you are hereby notified that any review, re-transmission, conversion to hard copy, copying, circulation or other use of this message and any attachments is strictly prohibited. If you are not the intended recipient, please notify the sender immediately by return email, and delete this message and any attachments from your system.
Virus Warning: Although I have taken reasonable precautions to ensure no viruses are present in this email, I cannot accept responsibility for any loss or damage arising from the use of this email or attachment."

Speak out for justice and peace,
even if your voice trembles.





From: tomasz jankowski <tomasz_jacek@wp.pl>
To: boost-users <Boost-users@lists.boost.org>
Sent: Thursday, 5 February, 2009 7:46:34 PM
Subject: [Boost-users] [boost-users][asio] why boost::thread thread1(boost::bind(...)) doesn't start io_service on multicore machine?

I would like to test my class which implements shared data.
because of it I have written test code which use boost::thread & boost
asio (please see below).
the problem is that threads are NOT started... on multicore machine.

one one core machine it runs fine.

any idea why?

tom


#include <iostream>
#include <istream>
#include <ostream>
#include <string>
#include <boost/asio.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/bind.hpp>
#include <boost/thread.hpp>
#include "shared.hpp"
#include <boost/random/linear_congruential.hpp>
#include <boost/random/uniform_real.hpp>
#include <boost/random/variate_generator.hpp>

SharedData replyToClients;

void handle_timeout1(const boost::system::error_code&)
{
  boost::minstd_rand generator(42u);
  boost::uniform_real<> uni_dist(0,1);
  boost::variate_generator<boost::minstd_rand, boost::uniform_real<>
>uni(generator, uni_dist);

  std::string key = "ello";std::cout<<key<<std::endl;
  std::string value1 = "see you later aligator";
  std::string value2 = "what do you want to eat today?";

  double cond = 0.500000;
  while(true){
    if(uni() >= cond){
      replyToClients.set(key,value1);
    }else{
      replyToClients.set(key,value2);
    }
  }
}
void handle_timeout2(const boost::system::error_code&)
{
  std::string key = "ello";

  while(true){
    std::cout<<replyToClients.get(key);
  }
}

int main(int argc, char* argv[])
{

    try{
    boost::asio::io_service io_service;
    boost::system::error_code error;
    //boost::asio::io_service::work work(io_service);

    io_service.post(boost::bind(handle_timeout1,error));
    io_service.post(boost::bind(handle_timeout2,error));
    io_service.post(boost::bind(handle_timeout2,error));
    io_service.post(boost::bind(handle_timeout2,error));

    boost::thread thread1(boost::bind(&boost::asio::io_service::run,
&io_service));
    boost::thread thread2(boost::bind(&boost::asio::io_service::run,
&io_service));
    boost::thread thread3(boost::bind(&boost::asio::io_service::run,
&io_service));
    boost::thread thread4(boost::bind(&boost::asio::io_service::run,
&io_service));

    //io_service.run();
    std::cout<<"the end\n";
    io_service.stop();
    thread1.join();
    thread2.join();
    thread3.join();
    thread4.join();
    }
  catch (boost::system::system_error& er)
  {std::cout << "Exception er: " << er.what() << "\n";
  }
  catch (std::exception& e)
  {
    std::cout << "Exception e: " << e.what() << "\n";
  }
  return 0;

}

----------------------------------------------------
Nużą Cię utarte scenariusze?
Wymyśl własną grę flashową i wygraj główną nagrodę 5.500 Euro:
http://klik.wp.pl/?adr=http%3A%2F%2Fwhosegame.pl%2Fcontestcard.php%3Fcontest%3D55&sid=631


Unlimited freedom, unlimited storage. Get it now