multithreading

send and receive request via sms instead of http

♀尐吖头ヾ 提交于 2020-01-25 18:06:06
问题 in my android application I want to send requests to server via sms if there was no internet connection or network. I am changing the Volley library code. http request is synchronous, when you send the request, thread waits until the response or error get received from server, but when you send sms, thread continue to work and doesn't wait to get the response sms so I am forced to use Callback functions(listeners). is there any better approach. is it good idea to use wait and notify to make

How to wait for Thread notification instead of joining all the Threads?

依然范特西╮ 提交于 2020-01-25 13:14:49
问题 In few words, a user makes a request to my web service, and I have to forward the request to X different APIs. I should do it on parallel, so I'm creating threads for this, and the first Thread that answers with a valid response, I should kill the rest of the threads and give back the answer to my customer right away. One common pattern in Ruby, is to create multiple threads like threads << Thread.new {} threads.each { |t| t.join } The logic I already have is something like: results = []

How to handle same socket in different threads?

爱⌒轻易说出口 提交于 2020-01-25 12:59:05
问题 I am trying to handle socket in different threads creating runtime failure. See following code. void MySocket::Lock() { m_LockCount++; if( m_LockCount ) { CSocket::Create( 8080 ); } } void MySocket::Unlock() { m_LockCount--; if( !m_LockCount ) { CSocket::Close(); } } I am calling Lock() from one thread and Unlock() from other. When it executes CSocket::Close() it gives an exception. I googled for this bug and got some reasons. This happens because; a CSocket object should be used only in the

c# wpf run button click on new thread

╄→гoц情女王★ 提交于 2020-01-25 12:44:25
问题 In my WPF, .Net 4.5 application I have some long running tasks that occur after user interactions. If for example a user clicks a button, whats the best way to run the button action on a separate thread so that the user can keep interacting with the application while the processing is being done? 回答1: For Long running tasks you can use async/await. It's designed to replace the background worker construct, but it's completely down to personal preference. here's an example: private int DoThis()

c# wpf run button click on new thread

这一生的挚爱 提交于 2020-01-25 12:44:25
问题 In my WPF, .Net 4.5 application I have some long running tasks that occur after user interactions. If for example a user clicks a button, whats the best way to run the button action on a separate thread so that the user can keep interacting with the application while the processing is being done? 回答1: For Long running tasks you can use async/await. It's designed to replace the background worker construct, but it's completely down to personal preference. here's an example: private int DoThis()

how to run the function in parallel?

拜拜、爱过 提交于 2020-01-25 12:09:40
问题 #define million 1000000L timer_t firstTimerID, secondTimerID, thirdTimerID; double Task2ms_Raster, Task10ms_Raster, Task100ms_Raster; struct sockaddr_in addr, client; int acceptSocket; char buf[256]; long rc, sentbytes; int port = 18033; void TASK1(Task2ms_Raster) { struct timespec start, stop; uint32 startTime, stopTime; if( (startTime = clock_gettime( CLOCK_REALTIME, &start)) == -1 ) { perror("clock gettime"); } startTime =start.tv_sec + 0.0000001 * start.tv_nsec; // printf("start time is

ISynchronizeInvoke vs SynchronizationContext vs mainForm.Invoke

怎甘沉沦 提交于 2020-01-25 11:42:05
问题 I have a Worker class and a MainForm/UI class. From the UI class I create a new instance of the Worker class in a new background thread. This thread marshals a few updates back to the UI's controls. Since they are in different classes I basically pass the MainForm instance (this) and an appropriate delegate to update the controls, into the worker class' constructor. In the constructor I set the mainForm to an ISynchronizeInvoke object (call it _synch) and then, further down in the worker

Multithreaded bundle and service instances

我是研究僧i 提交于 2020-01-25 10:40:08
问题 Assume I have 3 bundles A , B and B1 . Bundle A is the starting point of my application. Bundle B provides the API of the service used by A . Bundle B1 is an implementation of the service. Basically, bundle A has a set of records that it processes one after the other. There is no order for processing the records. I would like to improve performance of my application by processing subsets of records concurrently. I thought about two different ways: multiple instances of bundle A and, bundle A

Network-related tasks on a separate thread

早过忘川 提交于 2020-01-25 10:24:27
问题 I currently have a Pollen class which is a class I wrote which uses the JSoup library to parse HTML. Also shown here is my PlaceholderFragment class. public static class PlaceholderFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final Button button = (Button) rootView.findViewById(R.id.button1); final TextView textview = (TextView) rootView.findViewById(R.id.textview1); button.setOnClickListener(new View

How to use several threads to run in parallel to execute a very heavy task

為{幸葍}努か 提交于 2020-01-25 10:09:45
问题 I need to execute a task which includes four steps. Each step relies on the result of previous one. Executing all steps in one thread needs long time. I want to use four threads and each one performs one step and use a buffer between neighboring two steps to store the result of the previous step. I am developing on Android platform using Java. Can anybody give me an example? Thanks a lot. YL 回答1: I was curious, how the (non magically parallel) code would look like using reactive streams in