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
93a8f3cd
Commit
93a8f3cd
authored
Jun 21, 2025
by
Щербинин Артем Владимирович
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
c1c0f8f6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
0 deletions
+28
-0
unsafe.py
Задание_2.2._ВСР_Щербинин_А._В./unsafe.py
+28
-0
No files found.
Задание_2.2._ВСР_Щербинин_А._В./unsafe.py
0 → 100644
View file @
93a8f3cd
import
threading
import
time
class
UnsafeSingleton
:
_instance
=
None
def
__new__
(
cls
):
if
cls
.
_instance
is
None
:
time
.
sleep
(
0.01
)
cls
.
_instance
=
super
(
UnsafeSingleton
,
cls
)
.
__new__
(
cls
)
return
cls
.
_instance
instances
=
[]
def
create_instance
():
instance
=
UnsafeSingleton
()
instances
.
append
(
instance
)
threads
=
[
threading
.
Thread
(
target
=
create_instance
)
for
_
in
range
(
10
)]
for
t
in
threads
:
t
.
start
()
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