Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5b0ce3e

Browse files
committed
Increase the number of possible random seeds per time period.
Commit197e4af refactored the initialization of the libc random()seed, but reduced the number of possible seeds values that could bechosen in a given time period. This negation of the effects ofcommit98c5065 was unintentional. Replace with code thatshifts the fast moving timestamp bits left, similar to the originalalgorithm (though not the previous float-tolerating coding, whichis no longer necessary).Author: Thomas MunroReported-by: Noah MischReviewed-by: Tom LaneDiscussion:https://postgr.es/m/20181112083358.GA1073796%40rfd.leadboat.com
1 parentaa55183 commit5b0ce3e

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

‎src/backend/postmaster/postmaster.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2525,8 +2525,16 @@ InitProcessGlobals(void)
25252525
random_start_time.tv_usec=0;
25262526
#endif
25272527

2528-
/* Set a different seed for random() in every backend. */
2529-
srandom((unsignedint)MyProcPid ^ (unsignedint)MyStartTimestamp);
2528+
/*
2529+
* Set a different seed for random() in every backend. Since PIDs and
2530+
* timestamps tend to change more frequently in their least significant
2531+
* bits, shift the timestamp left to allow a larger total number of seeds
2532+
* in a given time period. Since that would leave only 20 bits of the
2533+
* timestamp that cycle every ~1 second, also mix in some higher bits.
2534+
*/
2535+
srandom(((unsignedint)MyProcPid) ^
2536+
((unsignedint)MyStartTimestamp <<12) ^
2537+
((unsignedint)MyStartTimestamp >>20));
25302538
}
25312539

25322540

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp