Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CSEP551
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Krishna Vinnakota
CSEP551
Commits
c2258bf4
Commit
c2258bf4
authored
17 years ago
by
rsc
Browse files
Options
Downloads
Patches
Plain Diff
fork minibug
parent
4f06ae0d
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
TRICKS
+24
-0
24 additions, 0 deletions
TRICKS
sysproc.c
+3
-1
3 additions, 1 deletion
sysproc.c
with
27 additions
and
1 deletion
TRICKS
+
24
−
0
View file @
c2258bf4
...
...
@@ -110,3 +110,27 @@ moves reads down after writes, but the language in
the spec allows it. There is no telling whether future
processors will need it.
---
The code in sys_fork needs to read np->pid before
setting np->state to RUNNABLE.
int
sys_fork(void)
{
int pid;
struct proc *np;
if((np = copyproc(cp)) == 0)
return -1;
pid = np->pid;
np->state = RUNNABLE;
return pid;
}
After setting np->state to RUNNABLE, some other CPU
might run the process, it might exit, and then it might
get reused for a different process (with a new pid), all
before the return statement. So it's not safe to just do
"return np->pid;".
This diff is collapsed.
Click to expand it.
sysproc.c
+
3
−
1
View file @
c2258bf4
...
...
@@ -7,12 +7,14 @@
int
sys_fork
(
void
)
{
int
pid
;
struct
proc
*
np
;
if
((
np
=
copyproc
(
cp
))
==
0
)
return
-
1
;
pid
=
np
->
pid
;
np
->
state
=
RUNNABLE
;
return
np
->
pid
;
return
pid
;
}
int
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment