Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
riscv-gcc-1
Overview
Overview
Details
Activity
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
riscv-gcc-1
Commits
691a924b
Commit
691a924b
authored
Mar 07, 2011
by
Ian Lance Taylor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid race condition manipulating heap when goroutine exits.
From-SVN: r170758
parent
457186f6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
8 deletions
+15
-8
libgo/runtime/go-go.c
+15
-8
No files found.
libgo/runtime/go-go.c
View file @
691a924b
...
...
@@ -92,25 +92,32 @@ remove_current_thread (void)
if
(
list_entry
->
next
!=
NULL
)
list_entry
->
next
->
prev
=
list_entry
->
prev
;
/* This will look runtime_mheap as needed. */
runtime_MCache_ReleaseAll
(
mcache
);
/* This should never deadlock--there shouldn't be any code that
holds the runtime_mheap lock when locking __go_thread_ids_lock.
We don't want to do this after releasing __go_thread_ids_lock
because it will mean that the garbage collector might run, and
the garbage collector does not try to lock runtime_mheap in all
cases since it knows it is running single-threaded. */
runtime_lock
(
&
runtime_mheap
);
mstats
.
heap_alloc
+=
mcache
->
local_alloc
;
mstats
.
heap_objects
+=
mcache
->
local_objects
;
__builtin_memset
(
mcache
,
0
,
sizeof
(
struct
MCache
));
runtime_FixAlloc_Free
(
&
runtime_mheap
.
cachealloc
,
mcache
);
runtime_unlock
(
&
runtime_mheap
);
/* As soon as we release this look, a GC could run. Since this
thread is no longer on the list, the GC will not find our M
structure, so it could get freed at any time. That means that
any code from here to thread exit must not assume that
the
m is
any code from here to thread exit must not assume that m is
valid. */
m
=
NULL
;
i
=
pthread_mutex_unlock
(
&
__go_thread_ids_lock
);
__go_assert
(
i
==
0
);
runtime_lock
(
&
runtime_mheap
);
mstats
.
heap_alloc
+=
mcache
->
local_alloc
;
mstats
.
heap_objects
+=
mcache
->
local_objects
;
__builtin_memset
(
mcache
,
0
,
sizeof
(
struct
MCache
));
runtime_FixAlloc_Free
(
&
runtime_mheap
.
cachealloc
,
mcache
);
runtime_unlock
(
&
runtime_mheap
);
free
(
list_entry
);
}
...
...
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