concurrency

concurrent access and free of heap object

随声附和 提交于 2020-01-06 01:45:14
问题 This question is a possible sub problem to this concurrent access and free of a data structure The other question is open to design, this one is more concrete. struct ds { int x,y,z; pthread_mutex_t mutex; }; I need a deterministic solution via which I can concurrently access 1 object of type ds and free it. Constrains: You can make mutex a pointer but can't take it out of the object. The real problem: Free can't be done holding the lock because, then memory occupied by the lock is also lost.

Illegal declaration in task definition

半世苍凉 提交于 2020-01-06 01:45:14
问题 I have the following task specification: with Ada.Real_Time; use Ada.Real_Time; package pkg_task is task type task_t is activationTime : constant Integer := 1; period : constant Integer := 2; computingTime : constant Integer := 1; startingTime : Time; end task_t; end pkg_task; When I compile I obtain the error mentioned on the title in all the lines of the task specification where I declare the variables, and I don't know what is the problem. 回答1: As Jacob wrote, you can't export anything

Performing a long calculation that returns after a timeout

半城伤御伤魂 提交于 2020-01-06 01:06:07
问题 I want to perform a search using iterative deepening, meaning every time I do it, I go deeper and it takes longer. There is a time limit (2 seconds) to get the best result possible. From what I've researched, the best way to do this is using an ExecutorService, a Future and interrupting it when the time runs out. This is what I have at the moment: In my main function: ExecutorService service = Executors.newSingleThreadExecutor(); ab = new AB(); Future<Integer> f = service.submit(ab); Integer

JavaFX - Concurrency and updating label

扶醉桌前 提交于 2020-01-05 13:12:21
问题 I've got problem with these piece of code. I want to make an application, which constatnly displays randomized values in labels as long as the Toggle Button is pressed. That's what I created, it works but window after a few seconds is lagging horrible. What am I doing wrong? Here is code of class, which generate random values: public class ValueMaker{ private StringPropterty x, y, z; private Random generator; private boolean isStarted = false; private int randomizedX(){ return generator

Code First - Retrieve and Update Record in a Transaction without Deadlocks

瘦欲@ 提交于 2020-01-05 10:24:41
问题 I have a EF code first context which represents a queue of jobs which a processing application can retrieve and run. These processing applications can be running on different machines but pointing at the same database. The context provides a method that returns a QueueItem if there is any work to do, or null, called CollectQueueItem . To ensure no two applications can pick up the same job, the collection takes place in a transaction with an ISOLATION LEVEL of REPEATABLE READ . This means that

Java JButton actionPerformed freezing

孤人 提交于 2020-01-05 10:11:34
问题 I've been fooling around with Java and I was trying to make a program that starts to ping an address and printing out the "ms". I have a JButton: JButton start = new JButton("START"); start.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ try { doCommand(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }); And the doCommand() method looks like this: public static void doCommand() throws IOException{ String s = null;

RxJava concurrency with multiple subscribers and events

為{幸葍}努か 提交于 2020-01-05 05:35:24
问题 I'm looking for a way to attach multiple subscribers to an RxJava Observable stream, with each subscriber processing emitted events asynchronously. I first tried using .flatMap() but that didn't seem to work on any subsequent subscribers. All subscribers were processing events on the same thread. .flatMap(s -> Observable.just(s).subscribeOn(Schedulers.newThread())) What ended up working was consuming each event in a new thread by creating a new Observable each time: Observable.from(Arrays

java: using volatile at one variable VS each variable

倾然丶 夕夏残阳落幕 提交于 2020-01-05 04:57:18
问题 the following problem: volatile Object A; volatile Object B; volatile Object C; Thread1: reads and writes to A-C Thread2: the same as Thread1 So my question is: would it better if i do something like this: Object A; Object B; Object C; volatile boolean memoryBarrier=true; Thread1: Before read of A-C: read memoryBarrier After some write of A-C: write memoryBarrier=true; Thread2: the same as Thread1: Before read of A-C: read memoryBarrier After some write of A-C: write memoryBarrier=true; Is

Aggregate root invariant enforcement with application quotas

ぐ巨炮叔叔 提交于 2020-01-05 04:57:13
问题 The application Im working on needs to enforce the following rules (among others): We cannot register a new user to the system if the active user quota for the tenant is exceeded. We cannot make a new project if the project quota for the tenant is exceeded. We cannot add more multimedia resources to any project that belongs to a tenant if the maximum storage quota defined in the tenant is exceeded The main entities involved in this domain are: Tenant Project User Resource As you can imagine,

Avoiding a possible concurrency issue with a LIST being returned

徘徊边缘 提交于 2020-01-05 04:33:08
问题 Here is the sequence that bother me begging a standard remedy for a concurrency issue Create a list object (lst) Initiate multple threads (Updater Threads) Send that lst to each Updater Threads to update (add) it. Wait for some defined time (t1) to let the Updater threads to proceed with updates. After t1 time expired, return lst to another application (Consumer-App) that isn't in our control. When return it, Updater Threads may be still updating the lst. Consumer-App doesn't know whether the