Boost logo

Boost Users :

From: Joshua Little (ljoshua_at_[hidden])
Date: 2004-06-26 01:24:32


Joshua Little wrote:

> Kent Holsinger wrote:
>
>> Joshua,
>>
>> The following works fine for me on Windows 2000 with GCC. It's just
>> your code turned into a complete program. That suggests the problem
>> is with your test case, not your use of the RNG.
>>
>> Note that this version will always produce the same output, since it
>> uses a default seed. If you want to produce different random
>> sequences, you'll need to seed the generator accordingly.
>>
>> Kent
>>
>> #include <iostream>
>> #include <boost/random.hpp>
>>
>> int main(int ac, char** av) {
>> printf(" Die \n ");
>> try {
>> boost::mt19937 rng;thin air
>> boost::uniform_int<> six(1,6);
>> boost::variate_generator<boost::mt19937, boost::uniform_int<> >
>> die(rng, six);
>> int x = die();
>> printf(" Die %d\n ",x);
>> }
>> catch(...) {
>> std::cout << "exception" << std::endl;
>> printf(" Die exception \n ");
>> }
>> }
>>
>>
> You were correct. I put that code into its own program and it ran just
> fine.. so I'm not sure what the deal is in my test cases, I don't know
> why it would kill the output since its basically the exact same code.
> This is the strangest thing I've seen in a while and I really have no
> idea what might be the problem.
>
> Joshua.

I hate to respond to my own mail but my brain woke up and I ran the test
through gdb and low and behold, in the test code its causing a segfault.
Program received signal SIGSEGV, Segmentation fault.
0x0046208f in
boost::variate_generator<boost::random::mersenne_twister<unsigned, 32,
624, 397, 31, 2567483615, 11, 7, 2636928640, 15, 4022730752, 18,
3346425566>, boost::uniform_int<int>
>::variate_generator(boost::random::mersenne_twister<unsigned, 32, 624,
397, 31, 2567483615, 11, 7, 2636928640, 15, 4022730752, 18, 3346425566>,
boost::uniform_int<int>) (this=0x22d150, e=
      {static word_size = <optimized out>, static state_size =
<optimized out>, static shift_size = <optimized out>, static mask_bits =
<optimized out>, static parameter_a = <optimized out>, static output_u =
<optimized out>, static output_s = <optimized out>, static output_b =
<optimized out>, static output_t = <optimized out>, static output_c =
<optimized out>, static output_l = <optimized out>, static
has_fixed_range = <optimized out>, x = {300933633, 1838352333,
1039116329, 1822211541, 2902250641, 835884317, 743498041, 2037202853,
140269601, 3129818989, 3468776265, 3042141813, 3597794481, 2144163517,
462622297, 2597716549, 3720499777, 3305777933, 2019631721, 1995498261,
1568860369, 1886915677, 891264889, 3303332069, 589975649, 2673363629,
1613469065, 3473388469, 3774879985, 1195980285, 56300697, 1687438213,
1437389441, 882253389, 3658296489, 1954175061, 3570011409, 3045544861,
2419715513, 1563345445, 3228719265, 1118971373, 2592237513, 3246084341,
2211530033, 1950934333, 3074468569, 2991510725, 2662556353, 2490032525,
681035497, 4253883797, 1377190225, 510946013, 3078867961, 1910438757,
2109239521, 2068762925, 2414463497, 3884072501, 1051296113, 1254122621,
94884121, 3726226949, 3738829569, 2310829261, 1386541353, 2138911445,
2779481489, 3853734429, 1575041593, 3616113829, 427858209, 2363640941,
2609232969, 284195701, 1112329649, 3416503229, 368346969, 2265507653,
2099557185, 3334395917, 2950212457, 2090768405, 1892538833, 2729970013,
2939566201, 1203920357, 3008287073, 1746966445, 2709143177, 3264874677,
2961123825, 4108767997, 2827668889, 3509610629, 1637315457, 1252395853,
1087829417, 3427093845, 1707163153, 2314637469, 2422654649, 2703066917,
195500449, 3938300653, 1324044489, 1985144309, 3691288113, 25018941,
1456382937, 2779003333, 892748737, 2712014477, 4014198761, 3670364821,
2278142545, 2900551645, 3747013881, 657391717, 3289215457, 527277613,
1509749513, 3673101109, 2292257393, 2841411965, 3542354457, 4067973893,
2718245889, 619897293, 3452123689, 3916605397, 1797994129, 972099357,
3001717561, 3263875493, 2667960865, 2112117101, 3251840329, 339906677,
723033777, 1635193021, 686751833, 3938503749, 2466780225, 985695501,
1475949673, 1319193877, 1965673169, 3163883101, 2600849785, 1086644965,
3222557281, 718660781, 244443017, 4213267893, 690961137, 2613145597,
4237526681, 1183944069, 1950553217, 2520971341, 2995371689, 3047506517,
470380305, 1564659101, 3767312313, 2490453029, 3955022497, 938885101,
2438805961, 1566538485, 430499633, 120561469, 3413482713, 2197724869,
1924801729, 2007907213, 3944274153, 1590855573, 655237969, 560882909,
3311599097, 354682213, 3347280609, 3824773933, 2757303305, 1037101109,
71934833, 3484786301, 737755929, 572260357, 3161539841, 3962982093,
944407337, 1602034901, 4001097617, 730582045, 3295472697,
3211857573...}, i = 624}, d={_min = 1, _max = 6, _range = 5})
    at e:/boost_1_31_0/boost/random/variate_generator.hpp:103
103 : _eng(decorated_engine(e)), _dist(d) { }
(gdb)

I'm hoping someone mught recognize this error and know what I can do to
fix it. This works fine in a stand alone app but it segfaults when its
used in my actual program. I do have an overloaded new operator but I
didn't see new mentioned in the stacktrace so I don't think thats whats
doing it but I may be wrong. I see the 'optomized out' stuff that I
guess might be causing the problem but thats also just a wild guess.
Anyone have any ideas?

Thanks,
Joshua.
 


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net