Search Results

Search found 1638 results on 66 pages for 'multithreading'.

Page 18/66 | < Previous Page | 14 15 16 17 18 19 20 21 22 23 24 25  | Next Page >

  • QT- QImage and multi-threading problem.

    - by umanga
    Greetings all, Please refer to image at : http://i48.tinypic.com/316qb78.jpg We are developing an application to extract cell edges from MRC images from electron microscope. MRC file format stores volumetric pixel data (http://en.wikipedia.org/wiki/Voxel) and we simply use 3D char array(char***) to load and store data (gray scale values) from a MRC file. As shown in the image,there are 3 viewers to display XY,YZ and ZX planes respectively. Scrollbars on the top of the viewers use to change the image slice along an axis. Here is the steps we do when user changes the scrollbar position. 1) get the new scrollbar value.(this is the selected slice) 2) for the relavant plane (YZ,XY or ZX), generate (char* slice;) array for the selected slice by reading 3D char array (char***) 3) Create a new QImage* (Format_RGB888) and set pixel values by reading 'slice' (using img-setPixel(x,y,c);) 4) This new QImage* is painted in the paintEvent() method. We are going to execute "edge-detection" process in a seperate thread since it is an intensive process.During this process we need to draw detected curve (set of pixels) on top of above QImage*.(as a layer).This means we need to call drawPoint() methods outside the QT thread. Is it the best wayto use QImage for this case? What is the best way to execute QT drawing methods from another thread? thanks in advance,

    Read the article

  • Entity Framework lazy loading doesn't work from other thread

    - by Thomas Levesque
    Hi, I just found out that lazy loading in Entity Framework only works from the thread that created the ObjectContext. To illustrate the problem, I did a simple test, with a simple model containing just 2 entities : Person and Address. Here's the code : private static void TestSingleThread() { using (var context = new TestDBContext()) { foreach (var p in context.Person) { Console.WriteLine("{0} lives in {1}.", p.Name, p.Address.City); } } } private static void TestMultiThread() { using (var context = new TestDBContext()) { foreach (var p in context.Person) { Person p2 = p; // to avoid capturing the loop variable ThreadPool.QueueUserWorkItem( arg => { Console.WriteLine("{0} lives in {1}.", p2.Name, p2.Address.City); }); } } } The TestSingleThread method works fine, the Address property is lazily loaded. But in TestMultiThread, I get a NullReferenceException on p2.Address.City, because p2.Address is null. It that a bug ? Is this the way it's supposed to work ? If so, is there any documentation mentioning it ? I couldn't find anything on the subject on MSDN or Google... And more importantly, is there a workaround ? (other than explicitly calling LoadProperty from the worker thread...) Any help would be very appreciated PS: I'm using VS2010, so it's EF 4.0. I don't know if it was the same in the previous version of EF...

    Read the article

  • Java synchronized seems ignored

    - by viraptor
    Hi, I've got the following code, which I expected to deadlock after printing out "Main: pre-sync". But it looks like synchronized doesn't do what I expect it to. What happens here? import java.util.*; public class deadtest { public static class waiter implements Runnable { Object obj; public waiter(Object obj) { this.obj = obj; } public void run() { System.err.println("Thead: pre-sync"); synchronized(obj) { System.err.println("Thead: pre-wait"); try { obj.wait(); } catch (Exception e) { } System.err.println("Thead: post-wait"); } System.err.println("Thead: post-sync"); } } public static void main(String args[]) { Object obj = new Object(); System.err.println("Main: pre-spawn"); Thread waiterThread = new Thread(new waiter(obj)); waiterThread.start(); try { Thread.sleep(1000); } catch (Exception e) { } System.err.println("Main: pre-sync"); synchronized(obj) { System.err.println("Main: pre-notify"); obj.notify(); System.err.println("Main: post-notify"); } System.err.println("Main: post-sync"); try { waiterThread.join(); } catch (Exception e) { } } } Since both threads synchronize on the created object, I expected the threads to actually block each other. Currently, the code happily notifies the other thread, joins and exits.

    Read the article

  • C# can I lock a method parameter?

    - by 5YrsLaterDBA
    We have a class variable ArrayList binaryScanData in a class. In all methods having access to it, we put lock(binaryScanData) on it because it is shared. Now we want to move one of those methods out to another util class to make it a static method. We will pass that binaryScanData into the method like this: public static void convertAndSaveRawData(ref MemoryStream output, ref ArrayList binaryScanData) Our questions are followed: how can we sychoronize that binaryScanData? can we do the same as it is originally? ref is necessary? It will only be read in that convertAndSaveRawData method.

    Read the article

  • Guaranteed semaphore order?

    - by Steve_
    The documentation for the .NET Semaphore class states that: There is no guaranteed order, such as FIFO or LIFO, in which blocked threads enter the semaphore. In this case, if I want a guaranteed order (either FIFO or LIFO), what are my options? Is this something that just isn't easily possible? Would I have to write my own Semaphore? I assume that would be pretty advanced? Thanks, Steve

    Read the article

  • Java ExecutorService java heap space ptoblems

    - by Sergey Aganezov jr
    I have a little bit of a problem in a multitasking java department. I have a class, called public class ThreadWorker implements Runnable { //some code in here public void run(){ // invokes some recursion method in the ThreadWorker itself, // which will stop eventually { } all in all, pretty simple "worker" that can work on it's on. To work with threads I'm using public static int THREAD_NUMBER = 4; public static ExecutorServide es = Executors.newFixedThreadPool(THREAD_NUMBER); adding instances of ThreadWroker class happens here: public void recursiveMethod(Arraylist<Integers> elements, MyClass data){ if (elements.size() == 0 && data.qualifies()){ ThreadWorker tw = new ThreadWorker(data); es.execute(tw); return; } for (int i=0; i< elements.size(); i++){ // some code to prevent my problem MyClass data1 = new MyClass(data); MyClass data2 = new MyClass(data); ArrayList<Integer> newElements = (ArrayList<Integer>)elements.clone(); data1.update(elements.get(i)); data2.update(-1 * elements.get(i)); newElements.remove(i); recursiveMethod(newElements, data1); recursiveMethod(newElements, data2); { } and the problem is that the depth of the recursion tree is quite big, so as it's width, so a lot of ThreadWorkers are added to the ExecutorService, so after some time on the big input a get Exception in thread "pool-1-thread-2" java.lang.OutOfMemoryError: Java heap space which is caused, as I think because of a ginormous number of ThreadWorkers i'm adding to ExecutorSirvice to be executed, so it runs out of memory. Every ThreadWorker takes about 40 Mb of RAM for all it needs. Is there a method to get how many threads (instances of classes implementing runnable interface) have been added to ExecutorService? So I can add it in the shown above code (int the " // some code to prevent my problem"), as while ("number of threads in the ExecutorService" > 10){ Thread.sleep(10000); } so I won't go to deep or to broad with my recursion and prevent those exception-throwing situations. Sincerely, Sergey Aganezov jr.

    Read the article

  • How to create a run loop that only listens to performSelector:onThread: and GUI events?

    - by Paperflyer
    I want to create a separate thread that runs its own window. Frankly, the documentation does not make sense to me. So I create an NSThread with a main function. I start the thread, create an NSAutoreleasePool, and run the run loop: // Global: BOOL shouldKeepRunning = YES; - (void)threadMain { NSAutoreleasePool *pool = [NSAutoreleasePool new]; // Load a nib file, set up its controllers etc. while (shouldKeepRunning) { NSAutoreleasePool *loopPool = [NSAutoreleasePool new]; [[NSRunLoop currentRunLoop] runUntilDate:[NSDate distantFuture]]; [loopPool drain]; } [pool drain]; } But since there is no registered port or observer, runUntilDate: exits immediately and CPU utilization goes to 100%. All thread communication is handled by calls to performSelector:onThread:withObject:waitUntilDone:. Clearly, I am not using the API correctly. So, what am I doing wrong?

    Read the article

  • Multi-threading mechanisms to run some lengthy operations from winforms code and communication with

    - by tmarouda
    What do I want to achieve: I want to perform some time consuming operations from my MDI winforms application (C# - .NET). An MDI child form may create the thread with the operation, which may take long time (from 0.1 seconds, to even half hour) to complete. In the meantime I want the UI to respond to user actions, including manipulation of data in some other MDI child form. When the operation completes, the thread should notify the MDI child that the calculations are done, so that the MDI child can perform the post-processing. How can I achieve this: Should I use explicit threading (i.e., create explicit threads), thread pools? Or simply just propose your solution. Should I create foreground or background threads? And how does the thread communicates with the GUI, according the solution you propose? If you know of a working example that handles a similar situation, please make a note.

    Read the article

  • Boost::Thread or fork() : Multithreaded HTTP Proxy

    - by osmano807
    I'm testing boost::thread on a system. It happens that I needed to act as a fork(), because one thread modifies the other variables, even member variables of class I do the project using fork() or is there some alternative still using boost::thread? Basically I run this program in Linux and maybe FreeBSD. It is an http proxy,accept() in main thread, and a function that accepts a class (where there is the file descriptor socket) in a secondary thread that makes the service. Is there a better way to implement a proxy?

    Read the article

  • LWUIT Deadlock (lwuit dialog VS System dialog)

    - by Ramps
    Hi, I have a deadlock problem when I try to make some I/O operations that needs user permission. When user click the button I start a new thread which is responsible for performing IO operations, and I display lwuit "please wait" dialog. Dialog is dismissed by IO thread from callback method. Problem is that, when system dialog appears (asking for user permission ) on top of lwuit dialog - deadlock occurs. I assume that this is because dialog.show() method blocks main thread (EDT), so it's impossible to dismiss system dialog, when lwuit dialog is behind it. Anyone managed to solve this problem? Here is the simplified code, hope it is clear enough: protected void actionPerformed(ActionEvent evt, int id) { switch (id) { case ID_FRIEND: MyRunnableWithIoOperation r = new MyRunnableWithIoOperation(this); new Thread(r).start(); //run the thread performing IO operations Command cmd = mWaitDialog.showDialog(); // show the "please wait" dialog ...//handle cancel }//end switch } /* method called from MyRunnableWithIoOperation, when operation finished*/ public void myCallbackMethod(){ mWaitDialog.dispose(); // } I tried to start my IO thread by calling Display.getInstance().invokeAndBlock( r ), but with no luck. In such case, my "wait dialog" doesn't show up.

    Read the article

  • Winforms application hungs when switching to another app

    - by joseluisrod
    Hi, I believe I have a potential threading issue. I have a user control that contains the following code: private void btnVerify_Click(object sender, EventArgs e) { if (!backgroundWorkerVerify.IsBusy) { backgroundWorkerVerify.RunWorkerAsync(); } } private void backgroundWorkerVerify_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { VerifyAppointments(); } private void backgroundWorkerVerify_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e) { MessageBox.Show("Information was Verified.", "Verify", MessageBoxButtons.OK, MessageBoxIcon.Information); CloseEvent(); } vanilla code. but the issue I have is that when the application is running and the users tabs to another application when they return to mine the application is hung, they get a blank screen and they have to kill it. This started when I put the threading code. Could I have some rogue threads out there? what is the best way to zero in a threading problem? The issue can't be recreated on my machine...I know I must be missing something on how to dispose of a backgroundworker properly. Any thoughts are appreciated, Thanks, Jose

    Read the article

  • Can a call to WaitHandle.SignalAndWait be ignored for performance profiling purposes?

    - by Dan Tao
    I just downloaded the trial version of ANTS Performance Profiler from Red Gate and am investigating some of my team's code. Immediately I notice that there's a particular section of code that ANTS is reporting as eating up to 99% CPU time. I am completely unfamiliar with ANTS or performance profiling in general (that is, aside from self-profiling using what I'm sure are extremely crude and frowned-upon methods such as double timeToComplete = (endTime - startTime).TotalSeconds), so I'm still fiddling around with the application and figuring out how it's used. But I did call the developer responsible for the code in question and his immediate reaction was "Yeah, that doesn't surprise me that it says that; but that code calls SignalAndWait [which I could see for myself, thanks to ANTS], which doesn't use any CPU, it just sits there waiting for something to do." He advised me to simply ignore that code and look for anything ELSE I could find. My question: is it true that SignalAndWait requires NO CPU overhead (and if so, how is this possible?), and is it reasonable that a performance profiler would view it as taking up 99% CPU time? I find this particularly curious because, if it's at 99%, that would suggest that our application is often idle, wouldn't it? And yet its performance has become rather sluggish lately. Like I said, I really am just a beginner when it comes to this tool, and I don't know anything about the WaitHandle class. So ANY information to help me to understand what's going on here would be appreciated.

    Read the article

  • Lock-free multi-threading is for real threading experts...

    - by vdhant
    I was reading through an answer that Jon Skeet gave to a question and in it he mentioned this: As far as I'm concerned, lock-free multi-threading is for real threading experts, of which I'm not one. Its not the first time that I have heard this, but I find very few people talking about how you actually do it if you are interested in learning how to write lock-free multi-threading code. So my question is besides learning all you can about threading, etc where do you start trying to learn to specifically write lock-free multi-threading code and what are some good resources. Cheers

    Read the article

  • Syncronization Exception

    - by Kurru
    Hi I have two threads, one thread processes a queue and the other thread adds stuff into the queue. I want to put the queue processing thread to sleep when its finished processing the queue I want to have the 2nd thread tell it to wake up when it has added an item to the queue However these functions call System.Threading.SynchronizationLockException: Object synchronization method was called from an unsynchronized block of code on the Monitor.PulseAll(waiting); call, because I havent syncronized the function with the waiting object. [which I dont want to do, i want to be able to process while adding items to the queue]. How can I achieve this? Queue<object> items = new Queue<object>(); object waiting = new object(); 1st Thread public void ProcessQueue() { while (true) { if (items.Count == 0) Monitor.Wait(waiting); object real = null; lock(items) { object item = items.Dequeue(); real = item; } if(real == null) continue; .. bla bla bla } } 2nd Thread involves public void AddItem(object o) { ... bla bla bla lock(items) { items.Enqueue(o); } Monitor.PulseAll(waiting); }

    Read the article

  • How can I dispatch an PropertyChanged event from a subscription to an Interval based IObservable

    - by James Hay
    I'm getting an 'UnauthorizedAccesExpection - Invalid cross-thread access' exception when I try to raise a PropertyChanged event from within a subscription to an IObservable collection created through Observable.Interval(). With my limited threading knowledge I'm assuming that the interval is happening on some other thread while the event wants to happen on the UI thread??? An explanation of the problem would be very useful. The code looks a little like: var subscriber = Observable.Interval(TimeSpan.FromSeconds(1)) .Subscribe(x => { Prop = x; // setting property raises a PropertyChanged event }); Any solutions?

    Read the article

  • Delegate within a delegate in VB.NET.

    - by Topdown
    I am trying to write a VB.NET alternative to a C# anonymous function. I wish to call Threading.SynchronizationContext.Current.Send which expects a delegate of type Threading.SendOrPostCallback to be passed to it. The background is here, but because I wish to both pass in a string to MessageBox.Show and also capture the DialogResult I need to define another delegate within. I am struggling with the VB.NET syntax, both from the traditional delegate style, and lambda functions. My go at the traditional syntax is below, but I have gut feeling it should be much simpler than this: Private Sub CollectMesssageBoxResultFromUserAsDelegate(ByVal messageToShow As String, ByRef wasCanceled As Boolean) wasCanceled = False If Windows.Forms.MessageBox.Show(String.Format("{0}{1}Please press [OK] to ignore this error and continue, or [Cancel] to stop here.", messageToShow), "Continue", Windows.Forms.MessageBoxButtons.OKCancel, Windows.Forms.MessageBoxIcon.Exclamation) = Windows.Forms.DialogResult.Cancel Then wasCanceled = True End If End Sub Private Delegate Sub ShowMessageBox(ByVal messageToShow As String, ByRef canceled As Boolean) Private Sub AskUserWhetherToCancel(ByVal message As String, ByVal args As CancelEventArgs) If args Is Nothing Then args = New System.ComponentModel.CancelEventArgs With {.Cancel = False} Dim wasCancelClicked As Boolean Dim firstDelegate As New ShowMessageBox(AddressOf CollectMesssageBoxResultFromUserAsDelegate) '…. Now what?? 'I can’t declare SendOrPostCallback as below: 'Dim myDelegate As New Threading.SendOrPostCallback(AddressOf firstDelegate) End Sub

    Read the article

  • async handler deleted by the wrong thread in django

    - by user3480706
    I'm run this algorithm in my django application.when i run several time from my GUI django local server will stopped and i got this error Exception RuntimeError: RuntimeError('main thread is not in main loop',) in ignored Tcl_AsyncDelete: async handler deleted by the wrong thread Aborted (core dumped) code print "Learning the sin function" network =MLP.MLP(2,10,1) samples = np.zeros(2000, dtype=[('x', float, 1), ('y', float, 1)]) samples['x'] = np.linspace(-5,5,2000) samples['y'] = np.sin(samples['x']) #samples['y'] = np.linspace(-4,4,2500) for i in range(100000): n = np.random.randint(samples.size) network.propagate_forward(samples['x'][n]) network.propagate_backward(samples['y'][n]) plt.figure(figsize=(10,5)) # Draw real function x = samples['x'] y = samples['y'] #x=np.linspace(-6.0,7.0,50) plt.plot(x,y,color='b',lw=1) samples1 = np.zeros(2000, dtype=[('x1', float, 1), ('y1', float, 1)]) samples1['x1'] = np.linspace(-4,4,2000) samples1['y1'] = np.sin(samples1['x1']) # Draw network approximated function for i in range(samples1.size): samples1['y1'][i] = network.propagate_forward(samples1['x1'][i]) plt.plot(samples1['x1'],samples1['y1'],color='r',lw=3) plt.axis([-2,2,-2,2]) plt.show() plt.close() return HttpResponseRedirect('/charts/charts') how can i fix this error ?need a quick help

    Read the article

  • Why isn't the reference counter in boost::shared_ptr volatile?

    - by Johann Gerell
    In the boost::shared_ptr destructor, this is done: if(--*pn == 0) { boost::checked_delete(px); delete pn; } where pn is a pointer to the reference counter, which is typedefed as shared_ptr::count_type -> detail::atomic_count -> long I would have expected the long to be volatile long, given threaded usage and the non-atomic 0-check-and-deletion in the shared_ptr destructor above. Why isn't it volatile?

    Read the article

  • How do I run different threads in Java?

    - by Cris Carter
    Hey. I'm having some problems with threads. I understand how they work, but since they all use the same method, how do I run different threads that do completely different things, but at the same time? To me, it seems that they always use the same standard method which makes them do the same thing. So, let's say I have a big .txt file where I want to go through each line and do something to the line. In this case, I would like to have each thread do 1/10th of the .txt file, but I don't understand how the threads can communicate with each other, and how they could organize so each thread does the right part? Could anyone explain or help me with this? Would be very much appreciated!

    Read the article

  • Seeking help with a MT design pattern

    - by SamG
    I have a queue of 1000 work items and a n-proc machine (assume n = 4).The main thread spawns n (=4) worker threads at a time ( 25 outer iterations) and waits for all threads to complete before processing the next n (=4) items until the entire queue is processed for(i= 0 to queue.Length / numprocs) for(j= 0 to numprocs) { CreateThread(WorkerThread,WorkItem) } WaitForMultipleObjects(threadHandle[]) The work done by each (worker) thread is not homogeneous.Therefore in 1 batch (of n) if thread 1 spends 1000 s doing work and rest of the 3 threads only 1 s , above design is inefficient,becaue after 1 sec other 3 processors are idling. Besides there is no pooling - 1000 distinct threads are being created How do I use the NT thread pool (I am not familiar enough- hence the long winded question) and QueueUserWorkitem to achieve the above. The following constraints should hold The main thread requires that all worker items are processed before it can proceed.So I would think that a waitall like construct above is required I want to create as many threads as processors (ie not 1000 threads at a time) Also I dont want to create 1000 distinct events, pass to the worker thread, and wait on all events using the QueueUserWorkitem API or otherwise Exisitng code is in C++.Prefer C++ because I dont know c# I suspect that the above is a very common pattern and was looking for input from you folks.

    Read the article

  • Hooking thread exit

    - by mackenir
    Is there a way for me to hook the exit of managed threads (i.e. run some code on a thread, just before it exits?) I've developed a mechanism for hooking thread exit that works for some threads. Step 1: develop a 'hook' STA COM class that takes a callback function and calls it in its destructor. Step 2: create a ThreadStatic instance of this object on the thread I want to hook, and pass the object a managed delegate converted to an unmanaged function pointer. The delegate then gets called on thread exit (since the CLR calls IUnknown::Release on all STA COM RCWs as part of thread exit). This mechanism works on, for example, worker threads that I create in code using the Thread class. However, it doesn't seem to work for the application's main thread (be it a console or windows app). The 'hook' COM object seems to be deleted too late in the shutdown process and the attempt to call the delegate fails. (The reason I want to implement this facility is so I can run some native COM code on the exiting thread that works with STA COM objects that were created on the thread, before it's 'too late' (i.e. before the thread has exited, and it's no longer possible to work with STA COM objects on that thread.))

    Read the article

  • How to stop worker threads in a multithreaded Windows service on service stop

    - by RobW
    I have a Windows service that uses the producer/consumer queue model with multiple worker threads processing tasks off a queue. These tasks can be very long running, in the order of many minutes if not hours, and do not involve loops. My question is about the best way to handle the service stop to gracefully end processing on these worker threads. I have read in another SO question that using thread.Abort() is a sign of bad design, but it seems that the service OnStop() method is only given a limited amount of time to finish before the service is terminated. I can do sufficient clean-up in the catch for ThreadAbortException (there is no danger of inconsistent state) so calling thread.Abort() on the worker threads seems OK to me. Is it? What are the alternatives?

    Read the article

  • What happens if two COM classes each without a threading model are implemented in one in-proc COM se

    - by sharptooth
    Consider a situation. I have an in-proc COM server that contains two COM classes. Both classes are marked as "no threading model" in the registry - the "ThreadingModel" value is just absent. Both classes read/write the same set of global variable without any synchronization. As far as I know "no threading model" will enforce COM to disallow concurrent access to the same or different instances of the same class by different threads. Will COM prevent concurrent access to instances of the two abovementioned different classes? Do I need synchronization when accessing the global variables from two different COM classes in this situation?

    Read the article

  • Getting IIS Worker Process Crash dumps

    - by CVertex
    I'm doing something bad in my ASP.NET app. It could be the any number of CTP libraries I'm using or I'm just not disposing something properly. But when I redeploy my ASP.NET to my Vista IIS7 install or my server's IIS6 install I crash an IIS worker process. I've narrowed the problem down to my HTTP crawler, which is a multithreaded beast that crawls sites for useful information when asked to. After I start a crawler and redeploy the app over the top, rather than gracefully unloading the appDomain and reloading, an IIS worker process will crash (popping up a crash message) and continue reloading the app domain. When this crash happens, where can I find the crash dump for analysis?

    Read the article

  • Gracefully exiting from thread in Ruby

    - by jasonbogd
    Hi, I am trying out Mongrel and using the following code: require 'rubygems' require 'mongrel' class SimpleHandler < Mongrel::HttpHandler def process(request, response) response.start(200) do |head, out| head["Content-Type"] = "text/plain" out.write("Hello World!\n") end end end h = Mongrel::HttpServer.new("0.0.0.0", "3000") h.register("/test", SimpleHandler.new) puts "Press Control-C to exit" h.run.join trap("INT") do puts "Exiting..." end Basically, this just prints out "Hello World!" when I go to localhost:3000/test. It works fine, and I can close the program with Control-C. But when I press Control-C, this gets outputted: my_web_server.rb:17:in `join': Interrupt from my_web_server.rb:17 So I tried putting that trap("INT") statement at the end, but it isn't getting called. Solution? Thanks.

    Read the article

< Previous Page | 14 15 16 17 18 19 20 21 22 23 24 25  | Next Page >