In Linux when a new process is created, it inherits the normal_prio value of it's parent process for it's static_prio. Where does this actually happen??
Is it done in dup_task_struct() function or in copy_process() function??
It actually happens in sched_fork which is called by copy_process
The parent's priority is transferred into the child initially something like this
p->prio = current->normal_prio;
where p is child's task_struct and current points to parent.
And then normal_prio is modified like this
p->prio = p->normal_prio = __normal_prio(p);
__normal_prio(p) finally boils down to something like
return p->static_prio;
Check out the 2 links I've added to explore more.
Related
Let's say I have a parent::Entity with zero or many good_child::Entity, neutral_child::Entity, and chaotic_child::Entity. (Just an example. The actual child_* tables have nothing in common with one another).
Each child has a field with its parent's id. Now I can select all good_children for some parent with
let (parent, good_children) = model::parent::Entity::find_by_id(42)
.find_with_related(model::good_child::Entity)
.all(&db.begin().await.map_err(…)?)
.await
.map_err(…)?
.pop()
.ok_or(…)?;
But how can I get the neutral and chaotic children in the same query? Simply adding another find_with_related() call does not work:
no method named find_with_related found for struct SelectTwoMany in the current scope
method not found in SelectTwoMany<…::parent::Entity, projektdb_model::good_child::Entity>
I want to create nodes programatically with its properties but using the folowing codes nodes can be created but its properties can not be set.
CreateUnspecifiedTypeRequest request_ch = new
CreateUnspecifiedTypeRequest(
Collections.singletonList(xxxElementTypes.yy),
diagramEditPart.getDiagramPreferencesHint());
Command command = diagramEditPart.getCommand(request);
command.execute();
then element.set("idof element") but the properties of the node still empty.
may someone help me .thanks
I am currently using this method in order to create nodes programatically. The node and the properties appear just fine and you can edit them. (note that there is also a way to edit the properties programmatically, with another type of command (EMF))
public void createAndExecuteShapeRequestCommand(IElementType type, EditPart parent) {
CreateViewRequest actionRequest = CreateViewRequestFactory
.getCreateShapeRequest(
type,
PreferencesHint.USE_DEFAULTS);
org.eclipse.gef.commands.Command command = parent.getCommand(actionRequest);
command.execute();
}
A sample caller of that method if the node is meant to be added in the main area of the diagram.
createAndExecuteShapeRequestCommand(xxx.diagram.providers.xxxElementTypes.ELEMENT_HERE, diagramEditPart);
A sample caller of that method if the node is meant to be added inside another node or compartment.
DiagramEditPart diagramEditPart = getDiagramEditPart(); //diagram.getDiagramEditPart();
"ParentElement" parentElement = (("Root_ELEMENT") diagramEditPart.resolveSemanticElement())."getTheElement"();
List list = getDiagramGraphicalViewer().findEditPartsForElement(EMFCoreUtil.
getProxyID(parentElement),
TheElementsEDITPART.class);
createAndExecuteShapeRequestCommand(xxx.diagram.providers.xxxElementTypes.ELEMENT_HERE, (EditPart)list.get(0));
Note that, if you wish to call this method from other class than the one of the xxxDiagramEditor.java you will need somehow to pass there the diagramEditPart.
Need your help with modules inheritance in Lua .
Let's say I've got 2 modules:
The 1st one is "Parent" It defines 1 field called "port" and method "connect" that uses port & domain fields to connect to some service. I wanna define the 2nd field (domain) in Child module, not in Parent one. Or at least to override this field by Child module.
module('Parent', package.seeall)
port = 1234
function connect()
ngx.say("connecting to "..domain..":"..port.."\n")
end
Note that "domain" variable is not defined here!
Now let's see the 2nd one, it's "Child":
local base = _G
module('Child', package.seeall)
local Parent = base.require('Parent')
base.setmetatable(Child, { __index = Parent })
domain = '127.0.0.1'
And here goes main lua code creating Child instance:
local Child = require "Child"
Child.connect()
The problem is that variable defined in Child module is invisible for the method defined in Parent module.. I need to change this behavior to let Parent routines code see variables defined in Child module.. Is that possible?
Can i copy Child's namespace to Parent module somehow?
I'm not particularly familiar with Lua modules, but it seems to me the right solution is to redefine the method as function connect(self) and then access port and domain off of self, which will be the package.
function connect(self)
ngx.say("connecting to "..self.domain..":"..self.port.."\n")
end
-- this could also be written as function Parent:connect()
...
local Child = require "Child"
Child:connect()
That's certainly how I'd do it if I were just setting up regular table inheritance without modules.
My application uses multiple threads with one managed object context per thread.
For clarity I will refer to the different managed object contexts as: moc1, moc2, ..., etc.
Let's assume we have two models with a simple one-many relationship:
User 1----* Document
When a user logs in I fetch the corresponding model from one of the contexts (eg. moc1).
(pseudo code)
UserModel *globalLoggedUser = ( Fetch the logged in user using moc1 )
I then store this user so that I can reference it later.
In another part of the application I need to loop through thousands of items from an array and create Document objects for it. Each document then needs to be bound to the current user. This happens in a different background thread (which has its own context)
for( NSString *documentName in documents) {
( Create new document using moc2 )
** THIS IS WHERE MY PROBLEM IS **
// What I currently do:
UserModel *tempUser = ( Fetch the logged in user using moc2 )
( bind new document to tempUser )
// What I would like to do:
( bind new document to globalLoggedUser )
// Note that in this case tempUser and globalLoggedUser are the same user, except they are attached to different contexts.
}
As you can see, I would like to avoid having to fetch a new user into the current context each time.
The problem is, globalLoggedUser is part of moc1, whereas the new document is part of moc2 (or moc3, moc4, etc, depends on the thread).
So what's the best way to go about this? How can I globally save/cache an object and then use that same object to bind relationships in different contexts without incurring a penalty of having to fetch each time?
Thanks for any help you can provide.
You are correct that you can't use the same NSManagedObject across threads.
From the Core Data Programming Guide:
Using thread confinement, you should not pass managed objects or managed object contexts between threads. To “pass” a managed object from one context another across thread boundaries, you either:
Pass its object ID (objectID) and use objectWithID: or existingObjectWithID:error: on receiving managed object context.
The corresponding managed objects must have been saved—you cannot pass the ID of a newly-inserted managed object to another context.
Execute a fetch on the receiving context.
I think you'd be fine if you just fetched the logged in user with moc2 before you run the 'document' loop, as I don't see any reason to do the fetch each time inside the loop. (Is there some reason you are doing that?)
Don't worry about binding anything to the UserModel from thread 1, the tempUser you get from moc2 is referencing the same data in the database as globalLoggedUser.
I'm wondering what the best design would be for persisteing a new child entity with NHibernate without accidentally overwriting the parent in the database.
The problem I have is that the child entity will look something like this:
class Child
{
Parent Parent;
// other fields
}
My problem is that the child has been supplied from the UI layer along with the ID of the parent, and that means that the Parent ref is basically uninitialized: It will have the ID populated but everything else null - because the only way to populate its fields would be an extra round trip to the database to read them.
Now if I call Session.SaveOrUpdate(child) on NHibernate, what's going to happen with the parent. I don't want NHibernate to cascade save the uninitialized parent since that would just destroy the data in the database. How would people approach this problem? Any best practices?
You must use the session.Load(parentid) to get the aggregate root. In contrast to the session.Get() method, this does not actually fetch any data from the database, it just instantiates a Parent proxy object used to add Child objects to the correct Parent in the DB (eg. get the foreign key correctly).
Your code would probably look something like:
// Set the Parent to a nhibernate proxy of the Parent using the ParentId supplied from the UI
childFromUI.Parent = Session.Load<Parent>(childFromUI.Parent.Id);
Session.Save(childFromUI);
This article explains Get/Load and the nhibernate caches really well
You should probably be working with the aggregate root (probably the Parent) when doing Saves (or SaveOrUpdates etc).
Why not just:
Fetch the parent object using the parent id you have in the child from the UI layer
Add the child to the parents 'children' collection
I think you have to overview your mapping configuration for nhibernate. If you have defined on the reference by the child to the parent that hi has to Cascade all, it will update it!
So if you say Cascade.None he will do nothing. All other are bad ideas. Because you allready has the information of this parent. So why read from db agane?!
If your models looks like this
class Parent
{
}
class Child
{
Parent myParent;
}
and you are trying to set the parent and save the child without having a full parent object, just the ID.
You could try this:
session.Lock(child.myParent, LockMode.None);
before saving, this should tell nhibernate that there are no changes to the parent object to persist and it should only look at the object for the Id to persist the association between Parent and Child