concurrency

How to pass parameters to a Thread object?

你离开我真会死。 提交于 2019-12-25 17:37:41
问题 I'm working with a C++ class-library that provides a Thread base-class where the user has to implement a run() method. Is there a recommended way on how to pass parameters to that run() method? Right now I prefer to pass them via the constructor (as pointers). 回答1: I'm not sure about C++, but that's how you would do it in Java. You'd have a class that extends Thread (or implements Runnable) and a constructor with the parameters you'd like to pass. Then, when you create the new thread, you

System.ServiceModel.FaultException - The process cannot access the file 'xxx' because it is being used by another process

余生长醉 提交于 2019-12-25 11:42:15
问题 I have a webservice WCF which log requests at the end of the process : public void xxxxx(string sXmlIn, out string sXmlOut) { [...] // log log.PrintDatas = bPrintDatas; log.sXmlIn = sXmlIn; log.sXmlOut = sXmlOut; log.error = error; log.toFile(); } Here is my Log class : public class LogFile { public String sXmlIn; public String sXmlOut; public Error error; private bool bPrintDatas; public bool PrintDatas { set { bPrintDatas = value; } } private bool bInitWs; public bool InitWs { get { return

Deadlock - Transfer Program [closed]

亡梦爱人 提交于 2019-12-25 09:44:16
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . I want to know why this program can have a deadlock void transfer(int from, into to, double amount) { sem_t *sem_from, *sem_to; sem_from=get_sem(from); //function that obtains the semaphore from bank account

ActiveRecord: Handling DB races among workers

…衆ロ難τιáo~ 提交于 2019-12-25 09:26:47
问题 I have a Rails 3 project running on top of PostgreSQL 9.0. Use Case: Users can request to follow Artists by name. To do this, they submit a list of names to a REST resource. If I can't find the Artist by name in the local collection, I consult last.fm for information about them, and cache that information locally. This process can take some time, so it is delegated to a background job called IndexArtistJob . Problem : IndexArtistJob will be run in parallel. Thus, it is possible that two users

How to init ManagedObjectContext on the right queue?

这一生的挚爱 提交于 2019-12-25 09:26:24
问题 Extremely need an advice, currently run out of ideas. I stack with core data concurrency related issue, to debug I use -"com.apple.CoreData.ConcurrencyDebug" and what I have: Stack: Thread 3 Queue: coredata(serial) 0 +[NSManagedObjectContext Multithreading_Violation_AllThatIsLeftToUsIsHonor ]: CoreData`-[NSManagedObjectContext executeFetchRequest:error:]: 1 -[NSManagedObjectContext executeFetchRequest:error:]: 2 NSManagedObjectContext.fetch (__ObjC.NSFetchRequest) throws -> Swift.Array: 3

Switch between Primary to Secondary source on Timeout in Java

自古美人都是妖i 提交于 2019-12-25 09:25:39
问题 I am developing an API which is dependent on two third party data sources - One is SOAP API (Primary source) and other is mssql database (secondary source). The problem is these two sources are not stable and which is impacting the API and other APIs in the eco-system due lot of thread waiting for the response for long ( its shooting JVM memory). I want to have an implementation which timeout primary data source after a certain amount of time if not responded and switches to secondary source

What does it mean that singleton DCL broken?

本小妞迷上赌 提交于 2019-12-25 08:59:37
问题 After reading dozens of articles about DCL. I feel that I should not use this concept without volatile.If I will not lead this technique my code will not thread save and very very bad according one hundreed different reasons. Recently I reread basics Happens Before and I have a bit another view Lets research singleton code listing: public class Singleton{ private static Something instance = null; public static Singleton getInstance() { if (instance == null) { // point 1 synchronized

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

Could not start more threads despite using Executors

冷暖自知 提交于 2019-12-25 08:38:30
问题 i have been advised to use Executors.newCachedThreadPool() which will be able to solve problems when over-spawning threads. However there is still an error when the number of threads is growing past a certain point. Is there anyway to allow a thread to wait itself while waiting for system resources to be available? [WARN ] Thread table can't grow past 16383 threads. [ERROR][thread ] Could not start thread pool-1-thread-16114. errorcode -1 Exception in thread "Main Thread" java.lang.Error:

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() {