Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 3

Qt-interest Archive, July 2007
QUuid


Message 1 in thread

Hello list,

I have issues with the following call:   QUuid::createUuid().toString();

call it once it gives an ID, call it 2nd time it gives an ID,
form calling it 3rd time and forward .....  it keeps returning the ID  
generated at step 2.

is this normal ?

--
 [ signature omitted ] 

Message 2 in thread

On Thu, July 12, 2007 17:09, Yong wrote:
> I have issues with the following call:   QUuid::createUuid().toString();
>
> call it once it gives an ID, call it 2nd time it gives an ID,
> form calling it 3rd time and forward .....  it keeps returning the ID
> generated at step 2.
>
> is this normal ?

No and I can't reproduce this. As far as I know the source code of QUuid
this is not possible unless your operating system has a truly and
horrifically broken "random number generator".

Please provide some minimal compilable example code to reproduce this
problem.

What version of Qt are you using?

On what operating system?

With which compiler?


    Konrad

--
 [ signature omitted ] 

Message 3 in thread

sure, sorry for not giving these parameters in the begining.

OS: Mac OS X 10.4.9
Qt: qt-mac-opensource-src-4.2.2

the call "QUuid::createUuid().toString()" is made once from within a  
QThread that is stared from a QCoreApplication.
the thread ends, and when there is another QThread started, the call  
is made again... and so on depends on how many times
a QThread object will be created.

the app is not doing something complex, just accidentally found this  
issue while investigating why data is not saved from the thread in a  
file that has as name the "Uuid" generated by the "QUuid::createUuid 
().toString()".  It turns out that the data is saved, and the content  
of the file was just replaces, because the generated "Uuid" is the  
same after the second call.

for the moment I can workaround this, but it is just not normal  
because I had no problems on other platforms with this call.


thanks


On 12 Jul 2007, at 18:59, Konrad Rosenbaum wrote:

> On Thu, July 12, 2007 17:09, Yong wrote:
>> I have issues with the following call:   QUuid::createUuid 
>> ().toString();
>>
>> call it once it gives an ID, call it 2nd time it gives an ID,
>> form calling it 3rd time and forward .....  it keeps returning the ID
>> generated at step 2.
>>
>> is this normal ?
>
> No and I can't reproduce this. As far as I know the source code of  
> QUuid
> this is not possible unless your operating system has a truly and
> horrifically broken "random number generator".
>
> Please provide some minimal compilable example code to reproduce this
> problem.
>
> What version of Qt are you using?
>
> On what operating system?
>
> With which compiler?
>
>
>     Konrad
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx  
> with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>

--
 [ signature omitted ] 

Message 4 in thread

Just a clue

it might be the case that I have to recompile QT after doing system  
updates ?


Begin forwarded message:

> From: Yong <Yanicher@xxxxxxxxx>
> Date: 12 July 2007 19:40:55 GMT+03:00
> To: qt-interest@xxxxxxxxxxxxx
> Subject: Re: QUuid
>
> sure, sorry for not giving these parameters in the begining.
>
> OS: Mac OS X 10.4.9
> Qt: qt-mac-opensource-src-4.2.2
>
> the call "QUuid::createUuid().toString()" is made once from within  
> a QThread that is stared from a QCoreApplication.
> the thread ends, and when there is another QThread started, the  
> call is made again... and so on depends on how many times
> a QThread object will be created.
>
> the app is not doing something complex, just accidentally found  
> this issue while investigating why data is not saved from the  
> thread in a file that has as name the "Uuid" generated by the  
> "QUuid::createUuid().toString()".  It turns out that the data is  
> saved, and the content of the file was just replaces, because the  
> generated "Uuid" is the same after the second call.
>
> for the moment I can workaround this, but it is just not normal  
> because I had no problems on other platforms with this call.
>
>
> thanks
>
>
> On 12 Jul 2007, at 18:59, Konrad Rosenbaum wrote:
>
>> On Thu, July 12, 2007 17:09, Yong wrote:
>>> I have issues with the following call:   QUuid::createUuid 
>>> ().toString();
>>>
>>> call it once it gives an ID, call it 2nd time it gives an ID,
>>> form calling it 3rd time and forward .....  it keeps returning  
>>> the ID
>>> generated at step 2.
>>>
>>> is this normal ?
>>
>> No and I can't reproduce this. As far as I know the source code of  
>> QUuid
>> this is not possible unless your operating system has a truly and
>> horrifically broken "random number generator".
>>
>> Please provide some minimal compilable example code to reproduce this
>> problem.
>>
>> What version of Qt are you using?
>>
>> On what operating system?
>>
>> With which compiler?
>>
>>
>>     Konrad
>>
>> --
>> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx  
>> with "unsubscribe" in the subject or the body.
>> List archive and information: http://lists.trolltech.com/qt-interest/
>>
>
> --
> Yong
>
>

--
 [ signature omitted ] 

Message 5 in thread

Yong wrote:
> Just a clue
>
> it might be the case that I have to recompile QT after doing system
> updates ?
>
>
> Begin forwarded message:
>
>> *From: *Yong <Yanicher@xxxxxxxxx <mailto:Yanicher@xxxxxxxxx>>
>> *Date: *12 July 2007 19:40:55 GMT+03:00
>> *To: *qt-interest@xxxxxxxxxxxxx <mailto:qt-interest@xxxxxxxxxxxxx>
>> *Subject: **Re: QUuid*
>>
>> sure, sorry for not giving these parameters in the begining.
>>
>> OS: Mac OS X 10.4.9
>> Qt: qt-mac-opensource-src-4.2.2
>>
>> the call "QUuid::createUuid().toString()" is made once from within a
>> QThread that is stared from a QCoreApplication.
>> the thread ends, and when there is another QThread started, the call
>> is made again... and so on depends on how many times 
>> a QThread object will be created.
>>
>> the app is not doing something complex, just accidentally found this
>> issue while investigating why data is not saved from the thread in a
>> file that has as name the "Uuid" generated by
>> the "QUuid::createUuid().toString()".  It turns out that the data is
>> saved, and the content of the file was just replaces, because the
>> generated "Uuid" is the same after the second call.
>>
>> for the moment I can workaround this, but it is just not normal
>> because I had no problems on other platforms with this call.
>>
>>
>> thanks
>>
>>
>> On 12 Jul 2007, at 18:59, Konrad Rosenbaum wrote:
>>
>>> On Thu, July 12, 2007 17:09, Yong wrote:
>>>> I have issues with the following call:  
>>>> QUuid::createUuid().toString();
>>>>
>>>> call it once it gives an ID, call it 2nd time it gives an ID,
>>>> form calling it 3rd time and forward .....  it keeps returning the ID
>>>> generated at step 2.
>>>>
>>>> is this normal ?
>>>
>>> No and I can't reproduce this. As far as I know the source code of QUuid
>>> this is not possible unless your operating system has a truly and
>>> horrifically broken "random number generator".
>>>
>>> Please provide some minimal compilable example code to reproduce this
>>> problem.
>>>
>>> What version of Qt are you using?
>>>
>>> On what operating system?
>>>
>>> With which compiler?
>>>
>>>
>>>     Konrad
>>>
>>> --
>>> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx
>>> <mailto:qt-interest-request@xxxxxxxxxxxxx> with "unsubscribe" in the
>>> subject or the body.
>>> List archive and information: http://lists.trolltech.com/qt-interest/
>>>
>>
>> -- 
>> Yong
>>
>>
>
> -- 
> Yong
>
>
Yong,

It sounds like perhaps the thread is only being created once (with the
QUuid call being in the constructor) and then being reused rather than
recreated.  I can't say for sure without seeing some code, so I second
the request for a minimal example of your QThread and
QUuid::createUuid() call.

You should not have to recompile Qt after system changes.  I have not
looked at the source for QUuid but I feel confident in saying it simply
uses a pseudo-random number generator provided by the system or several
pseudo-random parameters of the system to generate part of the UUID.


Stuart

Attachment:

Attachment: signature.asc
Description: OpenPGP digital signature


Message 6 in thread

On Thursday 12 July 2007, Yong wrote:
> the app is not doing something complex, just accidentally found this
> issue while investigating why data is not saved from the thread in a
> file that has as name the "Uuid" generated by the "QUuid::createUuid
> ().toString()".  It turns out that the data is saved, and the content
> of the file was just replaces, because the generated "Uuid" is the
> same after the second call.

Hmm, I should mention that UUIDs are NOT guaranteed to be unique. They are 
just very likely to be unique. The likelyhood of two UUIDs crashing 
(collision probability) is round about in the range of 1 in 2^30 up to 1 in 
2^48 depending on the implementation and the underlying random number 
generator.

So if you DEPEND on those files being unique you should actually do a check 
before writing the file:

int ctr=0;//safety measure counter
while(1){
	//generate new file name
	QFile file(QUuid::createUuid().toString());
	//check existence
	if(file.exists()){
		//check for safety, 
		ctr++;
		//this should never trigger unless UUID space is exhausted:
		if(ctr>1000)
			qFatal("Tried to get fresh UUID for 1000 times. Didn't get one. Dying of 
despair.");
		continue;
	}
	/*... write file ...*/
	break;//stop on success
}



	Konrad

Attachment:

Attachment: pgpJyBDiK4p2k.pgp
Description: PGP signature


Message 7 in thread

> sure, sorry for not giving these parameters in the begining.
> 
> OS: Mac OS X 10.4.9 Qt: qt-mac-opensource-src-4.2.2
> 
> the call "QUuid::createUuid().toString()" is made once from within
> a QThread that is stared from a QCoreApplication. the thread ends,
> and when there is another QThread started, the call is made
> again... and so on depends on how many times a QThread object will
> be created.
> 
> the app is not doing something complex, just accidentally found
> this issue while investigating why data is not saved from the
> thread in a file that has as name the "Uuid" generated by the
> "QUuid::createUuid().toString()".  It turns out that the data is 
> saved, and the content of the file was just replaces, because the 
> generated "Uuid" is the same after the second call.
> 
> for the moment I can workaround this, but it is just not normal
> because I had no problems on other platforms with this call.

QUuid::createUuid() uses srand which is primed with the current 
timestamp. This will very likely make your Uuid unique, when used in 
the right way.

However, I assume that your threads are short lived, and new threads 
created very quickly, so the QUuids are actually seeded with the same 
timestamp for several of your threads; which will likely give you 
non-unique Uuids (on certain platforms with bad pseudo random 
generators). Linux and Windows have very good random generators (and 
Windows doesn't get primed with the timestamp), so that leaves the Mac 
(and older unix) platform which you're reporting the problem on.

I suggest that you only use one QUuid, and serialize the access to it 
cross threads. Generating a new Uuid shouldn't take took look so that 
it holds up your thread that much, and always provide you with a good 
result. However, if your threads are start with more than 1sec delay 
it shouldn't be a problem.

-- 
 [ signature omitted ] 

Attachment: signature.asc
Description: OpenPGP digital signature


Message 8 in thread

> suggest that you only use one QUuid

yes this is what I did, though when doing this was thinking that this  
might be better to be done in implementation of "QUuid" because it is  
a kind of type that has to behave like this.   Imagine I write a  
small DB engine with primary keys within tables being "Uuid" (mine  
was like one) and the records start vanishing - ouch.


thanks.


On 13 Jul 2007, at 10:48, Marius Storm-Olsen wrote:

>> sure, sorry for not giving these parameters in the begining.
>> OS: Mac OS X 10.4.9 Qt: qt-mac-opensource-src-4.2.2
>> the call "QUuid::createUuid().toString()" is made once from within
>> a QThread that is stared from a QCoreApplication. the thread ends,
>> and when there is another QThread started, the call is made
>> again... and so on depends on how many times a QThread object will
>> be created.
>> the app is not doing something complex, just accidentally found
>> this issue while investigating why data is not saved from the
>> thread in a file that has as name the "Uuid" generated by the
>> "QUuid::createUuid().toString()".  It turns out that the data is  
>> saved, and the content of the file was just replaces, because the  
>> generated "Uuid" is the same after the second call.
>> for the moment I can workaround this, but it is just not normal
>> because I had no problems on other platforms with this call.
>
> QUuid::createUuid() uses srand which is primed with the current  
> timestamp. This will very likely make your Uuid unique, when used  
> in the right way.
>
> However, I assume that your threads are short lived, and new  
> threads created very quickly, so the QUuids are actually seeded  
> with the same timestamp for several of your threads; which will  
> likely give you non-unique Uuids (on certain platforms with bad  
> pseudo random generators). Linux and Windows have very good random  
> generators (and Windows doesn't get primed with the timestamp), so  
> that leaves the Mac (and older unix) platform which you're  
> reporting the problem on.
>
> I suggest that you only use one QUuid, and serialize the access to  
> it cross threads. Generating a new Uuid shouldn't take took look so  
> that it holds up your thread that much, and always provide you with  
> a good result. However, if your threads are start with more than  
> 1sec delay it shouldn't be a problem.
>
> -- 
> .marius
>

--
 [ signature omitted ] 

Message 9 in thread

Only the first thread will be seeded when using QUuid::createUuid().
Subsequent threads will not be reseeded.  This appears to be due to
the static variable used to determine whether or not seeding has taken
place.

On 7/13/07, Marius Storm-Olsen <marius@xxxxxxxxxxxxx> wrote:
> > sure, sorry for not giving these parameters in the begining.
> >
> > OS: Mac OS X 10.4.9 Qt: qt-mac-opensource-src-4.2.2
> >
> > the call "QUuid::createUuid().toString()" is made once from within
> > a QThread that is stared from a QCoreApplication. the thread ends,
> > and when there is another QThread started, the call is made
> > again... and so on depends on how many times a QThread object will
> > be created.
> >
> > the app is not doing something complex, just accidentally found
> > this issue while investigating why data is not saved from the
> > thread in a file that has as name the "Uuid" generated by the
> > "QUuid::createUuid().toString()".  It turns out that the data is
> > saved, and the content of the file was just replaces, because the
> > generated "Uuid" is the same after the second call.
> >
> > for the moment I can workaround this, but it is just not normal
> > because I had no problems on other platforms with this call.
>
> QUuid::createUuid() uses srand which is primed with the current
> timestamp. This will very likely make your Uuid unique, when used in
> the right way.
>
> However, I assume that your threads are short lived, and new threads
> created very quickly, so the QUuids are actually seeded with the same
> timestamp for several of your threads; which will likely give you
> non-unique Uuids (on certain platforms with bad pseudo random
> generators). Linux and Windows have very good random generators (and
> Windows doesn't get primed with the timestamp), so that leaves the Mac
> (and older unix) platform which you're reporting the problem on.
>
> I suggest that you only use one QUuid, and serialize the access to it
> cross threads. Generating a new Uuid shouldn't take took look so that
> it holds up your thread that much, and always provide you with a good
> result. However, if your threads are start with more than 1sec delay
> it shouldn't be a problem.
>
> --
> .marius
>
>
>

--
 [ signature omitted ]