## multithreading – What is the best way to decouple and define the orchestration (coordination) of concurrent tasks?

I have a data synchronisation concurrent algorithm. It does the following: get data and files from server, send data and files to server, save them to database / filesystem. Imagine the system like this:

1. You have 1000 functions. Each one does some atomic operation. For instance, fetch latest objects of type X and insert them into DB; upload this file of type Y and so on. Each function is independent and can act on its own, it does not communicate with or affect other functions. On the other hand, none of them is a pure function, because they all use theese common resources (fetching data from the server, puting data on DB, saving files on filesystem)
2. You have a single entry point for the sychronization mechanism. The outside of the sync system can start the sync, say, by doing a Sync.start() call. Also, the sync has a single exit point. The sync can finish with either success, either failure (if any of those functions from (1) fail, the whole sync will fail). The ouside of the sync system can subscribe to onSyncSuccess / onSyncError events.
3. You have this black box in the middle of the system. This could be, for instance, a single threaded algorithm calling those 1000 functions from (1). But I made it concurrent.

Now consider this. This concurrent algorithm right now is rigid because the way in which the functions are called is hardcoded. If I want to take a bunch of functions from (1) that right now are executing sequentially, and if I want to make them execute parallel, it would be impossible without refactoring the whole class hierarchy.

I was thinking about the concept of direct acyclic graphs, and I made my own domain-specific language in Kotlin to define such task graphs. Now I could write the whole orchestration declaratively like this:

``````notifySyncWasStarted()
runSequentialy {
runInParallel {
}
}
notifySyncWasStopped()
``````

So first task1 gets executed, then task2 and 3 in the same time, then task4. By keeping this graph in a single file, I could easily modify the way tasks are executed. For instance, I could easily swap tasks:

``````notifySyncWasStarted()
runSequentialy {
runInParallel {
}
}
notifySyncWasStopped()
``````

Here, (task 4 and 2) gets executed, then 3, then 1. This works by using the fork-join paradigm, I create threads then join them into the parent thread.

In contrast, right now, the algorithm is spread around multiple classes, each of them was designed to run the tasks in a specific manner. Changing how tasks are ran would mean to refactor the classes and how they communicate to each other.

The question is: What is the best way to decouple and define the orchestration (coordination) of concurrent tasks? So that this orchestration could be easily changed in the future? Is my solution optimal or the way to go (direct acyclic graphs, fork-join, plus a domain specific language)? Or maybe there are some other design patterns that do the same thing?

## mathematical optimization – How to define the judgment function of extremum points

I encountered a problem in solving the math problem in China’s 2019 postgraduate entrance examination.

I need to judge whether $$f(x)=left{begin{array}{cc} x|x|, & x leq 0 \ x ln x, & x>0 end{array}right.$$ is differentiable at the point x = 0 and whether it is an extreme point.

The code in this post can be used to judge whether it is differentiable or not:

``````differentiableQ(f_, spec : (v_ -> v0_)) :=
With({jac = D(f, {v})},
Module({f0, jac0}, {f0, jac0} = {f, jac} /. Thread(spec);
VectorQ(Flatten@{f0, jac0}, NumericQ) &&
Limit((f - f0 - jac0.(v - v0))/Sqrt@Total((v - v0)^2), spec) ===
0) /; VectorQ(jac));
ClearAll(differentiableQ, dLimit);
differentiableQ(f_, spec : (v_ -> v0_)) :=
With({jac = D(f, {v})},
Module({f0, jac0, res}, {f0, jac0} = {f, jac} /. Thread(spec);
If(VectorQ(Flatten@{f0, jac0}, NumericQ),
res = Limit((f - f0 - jac0.(v - v0))/Sqrt@Total((v - v0)^2),
spec) /.
HoldPattern(Limit(df_, s_)) /; ! FreeQ(df, Piecewise) :>
With({L = dLimit(df, s)}, L /; FreeQ(L, dLimit));
res =
FreeQ(res, Indeterminate) && And @@ Thread(Flatten@{res} == 0),
res = False)) /; VectorQ(jac));
dLimit(df_, spec_) :=
Module({f0, jac0, pcs = {}, z, res},
pcs = Replace((*Solve(..,Reals) separates PW fn*)
z /. Solve(z == df, z,
Reals), {ConditionalExpression(y_, c_) :> {y, c},
y_ :> {y, True}}, 1);
If(ListQ(pcs),
res = (Limit(Piecewise({#}), spec) /.
HoldPattern(Limit(Piecewise({{y_, _}}, 0), s_)) :>
With({L = Limit(y, s)}, L /; FreeQ(L, Limit)) & /@ pcs));
res /; ListQ(pcs));

f(x_) := Piecewise({{x*RealAbs(x), x <= 0}, {x*Log(x), x > 0}})
differentiableQ(f(x), {x} -> {0})
``````

Now I want to judge whether the point x = 0 is the extreme point of function $$f(x)=left{begin{array}{cc} x|x|, & x leq 0 \ x ln x, & x>0 end{array}right.$$ .
However, MMA has no built-in function to determine whether a point is an extreme point. How to define a custom function to determine the extreme point?

## ag.algebraic geometry – How did Jouanolou define the cup product with no finiteness hypotheses in SGA 5?

In SGA 5 Exposé VII, at the beginning of §2, Jouanolou lets $$X$$ and $$Y$$ denote two schemes, $$f:Xrightarrow Y$$ a morphism, and $$A$$ the ring $$mathbf{Z}/numathbf{Z}$$ where $$nu$$ is an integer prime to the residual characteristics of $$X$$ and $$Y$$. He defines an arrow
$$Rf_*(A_X)otimes^L Rf_*(A_X)to Rf_*(A_X)tag{*}$$
by first defining an arrow
$$f_*C^cdot(X,A_X)otimes f_*C^cdot(X,A_X)to f_*C^cdot(X,A_X)$$
where $$C^cdot(X,A_X)$$ is the Godement resolution of the sheaf $$A_X$$ so that $$f_*C^cdot(X,A_X)$$ computes $$Rf_*(A_X)$$.
He then writes that one can obtain (*) using flat resolutions of the components on the left. Under some finiteness hypotheses that assure that $$Rf_*(A_X)$$ is in $$D^-(X)$$, I see this no problem. Actually, using the result of Spaltenstein published in ’88, one can use a K-flat resolution to define $$otimes^L$$ on all of $$D(X)times D(X)$$, but this definition hadn’t been made by the time Jouanolou’s exposé was published. So, what did Jouanolou have in mind here? Thanks for your help!

## Define a linear operator which has as Kernel the line y=-x and as image the line y=x

So the question asks basically to determine a linear operator $$F: mathcal{R}^2 rightarrow mathcal{R}^2$$ which has as Kernel the line y=-x and as image the line y=x.

Here is what i tried: i supposed i could write the operator in the form $$F(x,y)=(ax+by,cx+dy)$$. Thus

$$Ker(F)$$={$$(x,y) in mathcal{R}^2 : (ax+by,cx+dy)=(0,0)$$}

and i defined a=b=1 and c=d=0, so that i would have

$$Ker(F)$$={$$(x,y) in mathcal{R}^2 : (x+y)=(0,0)$$}

and the solution is x=-y if i’m not wrong. But for the image with these same guesses i got

$$Im(F)$$={$$(x+y,0) : (x,y) in mathcal{R}^2$$}
={$$(x+y)(1,0) : (x,y) in mathcal{R}^2$$}

But idk if i can conclude that the image is y=x. I don’t have arguments to support it or i’m just wrong in my trial. Any help would be great, thank you

## bash – Define cd so that it changes a variable (as it does already with PWD, OLDPWD, …)

My target is to have an environment variable being set to a leading substring of `\$PWD` and to be unset when `\$PWD` does not start with that substring.

So I decided to override `cd` like this (here I’m assuming the substring is just my home directory `/home/enrico`, but in general is fine for me that it be an hardcoded regex):

``````cd() {
command cd "\$@"
export MYVARIABLE=\$(<<< \$PWD sed -E 's!(/home/enrico)(/?\$|.*)!1!')
if (( \$MYVARIABLE == \$PWD )); then
unset MYVARIABLE
fi
}
``````

This seems to work fine, but I’d like to have some different point of view on it.

(Btw, if there are appropriate tags to add, please do, as I haven’t found any more than `bash`.)

## Define a function as the partial derivative of another

I just want to write something like

``````f[x_] := x[[1]]^2 + x[[2]]^3
g[x_] := D[f[y], {y}] /. y -> x
``````

I know this is probably very wrong in many ways but I am quite new to mathematica. I just want to know how to define the partial derivative of functions.

## c++ – Can someone define main() method of the below code.The code below shows the class definition for a stack with no race conditions

The code below shows the class definition for a stack with no race conditions in the interface and that implements options 1 and 3: there are two overloads of pop(), one that takes a reference to a location in which to store the value and one that returns a std::shared_ ptr<>. It has a simple interface, with only two functions: push() and pop().

``````#include<exception>
#include<memory>
#include<mutex>
#include<stack>
using namespace std;

struct empty_stack:exception{
const char* what() const throw();
};

template<typename T>
private:
stack<T> data;
mutable mutex m;
public:
lock_guard<mutex> lock(obj.m);
data=obj.data;
}
void push(T val){
lock_guard<mutex> lock(m);
data.push(val);
}

shared_ptr<T> pop(){
lock_guard<mutex> lock(m);
if(data.empty()) throw empty_stack();
shared_ptr<T> const res(make_shared<T> (data.top()) );
data.pop();
return res;
}

void pop(T& val){
lock_guard<mutex> lock(m);
val=data.top();
data.pop();
}

void empty() const{
lock_guard<mutex> lock(m);
return data.empty();
}
};
``````

## general topology – Properties need to define Derivatives on Topological space

I just started learning topology and was curious about defining derivatives on general topological spaces.
Since we can define continuous functions on Topological spaces, my question is what additional properties one would need to define derivatives on Topological spaces.

I guessed one might only need converging sequences to define derivative, so space must have,

1. metrizablity: to define some sort of distance between points so one can define converging sequences on space.
2. Hausdorff property: so convergence would be unique.

but on the other hand, these properties are conserved under homeomorphism, where differentiability does not.
so, there should be some more properties (maybe other than topological properties) one would need to define derivatives, and I’m not sure what kind of property it would be that conserves differentiability.

I hope my question makes sense.
Thanks.

## sharepoint online – SPFx define custom config folder for building solution

Is it possible, to somehow define which config folder gulp will take while bundling. Saying i will have a build script for each sppkg solutions

``````gulp clean && gulp bundle --ship && gulp package-solution --ship --cfg-webpart-one
``````

and gulp then knows that he take config-webpart-one folder which contain package-solution.json and config.json, configured for webpart-one bundle.

Default folder structure is:

``````config
src
...
``````

With multiple configs will be

``````config-webpart-one
config-webpart-two
src
...
``````

I appreciate any help. Thank you!

## magento2 – Short array syntax must be used to define arrays Use ::class notation instead

``````  90 | WARNING | ( ) Use ::class notation instead.
92 | WARNING | (x) Short array syntax must be used to define arrays
94 | WARNING | ( ) Use ::class notation instead.
96 | WARNING | (x) Short array syntax must be used to define arrays
98 | WARNING | ( ) Use ::class notation instead.
100 | WARNING | (x) Short array syntax must be used to define arrays
102 | WARNING | ( ) Use ::class notation instead.

``````
``````'value' => array(
array(
'label' => __('Is New (by a period)'),
'value' => 'AmastyXlandingModelRuleConditionIsNewByPeriod',
),
array(
'label' => __('Is New (by 'is_new' attribute)'),
'value' => 'AmastyXlandingModelRuleConditionIsNew',
),
array(
'label' => __('Created (in days)'),
'value' => 'AmastyXlandingModelRuleConditionCreated',
),
array(
'label' => __('In Stock'),
'value' => 'AmastyXlandingModelRuleConditionInStock',
),
``````

and modified them like that

``````(
'label' => __('Is New (by a period)'),
'value' => 'AmastyXlandingModelRuleConditionIsNewByPeriod',
),
(
'label' => __('Is New (by 'is_new' attribute)'),
'value' => 'AmastyXlandingModelRuleConditionIsNew',
),
(
'label' => __('Created (in days)'),

'value' => 'AmastyXlandingModelRuleConditionCreated',
),
``````

but still have those warnings and can’t pass pipeline

``````  88 | WARNING | ( ) Use ::class notation instead.
92 | WARNING | ( ) Use ::class notation instead.
96 | WARNING | ( ) Use ::class notation instead.

``````

how can I fix this?