Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
cc20b76a
Kaydet (Commit)
cc20b76a
authored
May 29, 1998
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Add comments explaining thread unsafety of this code.
üst
d03e1197
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
0 deletions
+10
-0
whrandom.py
Lib/whrandom.py
+10
-0
No files found.
Lib/whrandom.py
Dosyayı görüntüle @
cc20b76a
...
...
@@ -29,6 +29,13 @@
# Adrian Baddeley.
# Multi-threading note: the random number generator used here is not
# thread-safe; it is possible that nearly simultaneous calls in
# different theads return the same random value. To avoid this, you
# have to use a lock around all calls. (I didn't want to slow this
# down in the serial case by using a lock here.)
class
whrandom
:
#
# Initialize an instance.
...
...
@@ -60,6 +67,8 @@ class whrandom:
# Get the next random number in the range [0.0, 1.0).
#
def
random
(
self
):
# This part is thread-unsafe:
# BEGIN CRITICAL SECTION
x
,
y
,
z
=
self
.
_seed
#
x
=
(
171
*
x
)
%
30269
...
...
@@ -67,6 +76,7 @@ class whrandom:
z
=
(
170
*
z
)
%
30323
#
self
.
_seed
=
x
,
y
,
z
# END CRITICAL SECTION
#
return
(
x
/
30269.0
+
y
/
30307.0
+
z
/
30323.0
)
%
1.0
#
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment