synchronization

Exception on Monitor.Exit in C#

五迷三道 提交于 2019-12-25 08:58:33
问题 This is a large multi-threaded project (which I didn't write) that I am fixing. The application hangs on some locks which I am tracking down. I went through and replaced all the "lock" statements with Monitor.TryEnter so I could set a wait period. I am occasionally getting an exception with the Monitor.Exit . The original style was private List<myClass> _myVar= new List<myClass>(); if (_myVar != null) { lock (_myVar) { _myVar = newMyVar; // Where newMyVar is another List<myClass> } } I

Why is `pthread_mutex_unlock` called before calling `pthread_cond_signal`?

ぐ巨炮叔叔 提交于 2019-12-25 08:50:15
问题 From The Art of Multiprocessor Programming, 1 #include <pthread.h> 2 #define QSIZE 16 3 typedef struct { 4 int buf[QSIZE]; 5 long head, tail; 6 pthread_mutex_t *mutex; 7 pthread_cond_t *notFull, *notEmpty; 8 } queue; 9 void queue_enq(queue* q, int item) { 10 // lock object 11 pthread_mutex_lock (q->mutex); 12 // wait while full 13 while (q->tail - q->head == QSIZE) { 14 pthread_cond_wait (q->notFull, q->mutex); 15 } 16 q->buf[q->tail % QSIZE] = item; 17 q->tail++; 18 // release lock 19

It is possible an synchronous mysql query in nodejs?

↘锁芯ラ 提交于 2019-12-25 08:29:06
问题 I try find solutions like "Promices" or modules like "synchronize" or "sync", but I donsen't fine a properly solution ): The way its I have like 10 tables 'user', 'data', 'game'. And functions like: getUsers(){} // UserTable getData(){} // DataModel getGames(){} // GameTable getUserByGames(){} // UserModel And some funtions have needs to return me a model or table... and in some cases I need that model or that 'answer' to make another query and another stuff. So, i need to do synchronous

best practice for data synchronization in nodejs

ⅰ亾dé卋堺 提交于 2019-12-25 08:17:11
问题 I'm trying to do some integration between two systems, and I've got some problems when it comes to synchronizing data. I am using nodejs and the database is mongodb or firebase . The scenario is described as below: systemA with dbA systemB with dbB Do the following: systemA sends a request (POST or PUT whatever) to systemB, the body is like this: { ..... fieldA1: valueA1, fieldA2: valueA2 ..... } then systemB needs to update several fields(fieldB1, fieldB2) in dbB according to the systemA

Java: wait for thread result without blocking UI?

非 Y 不嫁゛ 提交于 2019-12-25 08:06:16
问题 Let me post some code before I ask question. public Object returnSomeResult() { Object o = new Object(); Thread thread = new Thread(this); thread.start(); return o; } public void run() { // Modify o. } So, the method returnSomeResult is called from UI thread; which starts another thread. Now, I need to wait until the thread finishes the calculation. And, meanwhile, I do not want to block UI thread. If I change code as below; the UI thread gets blocked. public Object returnSomeResult() {

Implementation of simple polling of results file

笑着哭i 提交于 2019-12-25 07:59:25
问题 For one of my dissertation's data collection modules, I have implemented a simple polling mechanism . This is needed, because I make each data collection request (one of many) as SQL query, submitted via Web form, which is simulated by RCurl code. The server processes each request and generates a text file with results at a specific URL ( RESULTS_URL in code below). Regardless of the request, URL and file name are the same (I cannot change that). Since processing time for different data

How I can iterate over an array and pass items to a method also all methods should run synchronously?

断了今生、忘了曾经 提交于 2019-12-25 07:27:58
问题 I want to call a request method that gets the body of itself as an array that is also one item of another array. so I should iterate over this parent array and pass its items to request method for a new request to server. I have used bodies.forEach but this make the calls async and I should also do something after every response and need sync calls. What is the best way to do this? bodies = [ [['name', 'Saeid'], ['age','23']], [['name', 'Saeid'], ['age', 23 ], ['city', 'Tehran']] ] bodies

Synchronizing two methods in Java

落花浮王杯 提交于 2019-12-25 07:17:48
问题 I have a class like this one: public class IClass{ public void draw(){...}; //is called periodically by the rendering thread public void foo(){...}; //is called asynchronously from another Thread(it could be an onTouchEvent() method for example) } I want the foo() method to wait until the draw method is finished and vice versa. How can I do this in Java? regards 回答1: Make the methods synchronized. public synchronized void draw() { System.out.println("draw"); } public synchronized void foo() {

Counter inside FSM in VHDL

浪子不回头ぞ 提交于 2019-12-25 05:36:07
问题 I have got a small problem with my finite state machine which I have written in VHDL recently. I tried to create "intelligent" counter triggered by clock with frequency 2 Hz. This counter is built in one state of FSM and is started by pushing a button on DE2 board. Firstly, whole system is in IDLE state and if I push this button, state is changed to COUNTING and counter begin to be incremented and his current value is shown on LED display. After it reach value of modulo, the state COUNTING is

Synchronization between threads using Critical Section

坚强是说给别人听的谎言 提交于 2019-12-25 05:31:29
问题 I have multiple threads, ThreadA and ThreadsB-Z. ThreadA is always in critical section, popping the data out of queue and sending it on socket. When any thread from ThreadB to ThreadZ want to enter the critical section, it wants ThreadA to leave critical section only then. It then enters the critical Section, push some data into queue and leaves critical section. I have two problems here: How would ThreadB-Z (whoever wants to enter the Critical Section) tell ThreadA to leave critical section