Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
2
2 Semester Practice 2
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Щербинин Артем Владимирович
2 Semester Practice 2
Commits
d3a9bea8
Commit
d3a9bea8
authored
Jun 21, 2025
by
Щербинин Артем Владимирович
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
349c3bbc
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
0 deletions
+34
-0
mult.py
Задание_2.2._ВСР_Щербинин_А._В./mult.py
+34
-0
No files found.
Задание_2.2._ВСР_Щербинин_А._В./mult.py
0 → 100644
View file @
d3a9bea8
import
threading
import
time
class
SafeSingleton
:
_instance
=
None
_lock
=
threading
.
Lock
()
def
__new__
(
cls
):
if
cls
.
_instance
is
None
:
with
cls
.
_lock
:
if
cls
.
_instance
is
None
:
time
.
sleep
(
0.01
)
cls
.
_instance
=
super
(
SafeSingleton
,
cls
)
.
__new__
(
cls
)
return
cls
.
_instance
instances
=
[]
def
create_instance
():
instance
=
SafeSingleton
()
instances
.
append
(
instance
)
if
__name__
==
"__main__"
:
threads
=
[
threading
.
Thread
(
target
=
create_instance
)
for
_
in
range
(
10
)]
for
t
in
threads
:
t
.
start
()
# time.sleep(0.01)
for
t
in
threads
:
t
.
join
()
unique_instances
=
set
(
instances
)
print
(
f
"Создано {len(unique_instances)} уникальных экземпляров Singleton."
)
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