Search Results

Search found 11135 results on 446 pages for 'thread safe'.

Page 10/446 | < Previous Page | 6 7 8 9 10 11 12 13 14 15 16 17  | Next Page >

  • Legacy application creates dialogs in non-ui thread.

    - by Frater
    I've been working support for a while on a legacy application and I've noticed a bit of a problem. The system is an incredibly complex client/server with standard and custom frameworks. One of the custom frameworks built into the application involves validating workflow actions. It finds potential errors, separates them into warnings and errors, and passes the results back to the client. The main difference between warnings and errors is that warnings ask the user if they wish to ignore the error. The issue I have is that the dialog for this prompt is created on a non-ui thread, and thus we get cross-threading issues when the dialog is shown. I have attempted to invoke the showing of the dialog, however this fails because the window handle has not been created. (InvokeRequired returns false, which I assume in this case means it cannot find a decent handle in its parent tree, rather than that it doesn't require it.) Does anyone have any suggestions for how I can create this dialog and get the UI thread to set it up and call it?

    Read the article

  • Is this (Lock-Free) Queue Implementation Thread-Safe?

    - by Hosam Aly
    I am trying to create a lock-free queue implementation in Java, mainly for personal learning. The queue should be a general one, allowing any number of readers and/or writers concurrently. Would you please review it, and suggest any improvements/issues you find? Thank you. import java.util.concurrent.atomic.AtomicReference; public class LockFreeQueue<T> { private static class Node<E> { E value; volatile Node<E> next; Node(E value) { this.value = value; } } private AtomicReference<Node<T>> head, tail; public LockFreeQueue() { // have both head and tail point to a dummy node Node<T> dummyNode = new Node<T>(null); head = new AtomicReference<Node<T>>(dummyNode); tail = new AtomicReference<Node<T>>(dummyNode); } /** * Puts an object at the end of the queue. */ public void putObject(T value) { Node<T> newNode = new Node<T>(value); Node<T> prevTailNode = tail.getAndSet(newNode); prevTailNode.next = newNode; } /** * Gets an object from the beginning of the queue. The object is removed * from the queue. If there are no objects in the queue, returns null. */ public T getObject() { Node<T> headNode, valueNode; // move head node to the next node using atomic semantics // as long as next node is not null do { headNode = head.get(); valueNode = headNode.next; // try until the whole loop executes pseudo-atomically // (i.e. unaffected by modifications done by other threads) } while (valueNode != null && !head.compareAndSet(headNode, valueNode)); T value = (valueNode != null ? valueNode.value : null); // release the value pointed to by head, keeping the head node dummy if (valueNode != null) valueNode.value = null; return value; }

    Read the article

  • Java static and thread safety or what to do

    - by Parhs
    I am extending a library to do some work for me. Here is the code: public static synchronized String decompile(String source, int flags,UintMap properties,Map<String,String> namesMap) { Decompiler.namesMap=namesMap; String decompiled=decompile(source,flags,properties); Decompiler.namesMap=null; return decompiled; } The problem is that namesMap is static variable. Is that thread safe or not? Because if this code runs concurently namesMap variable may change. What can I do for this?

    Read the article

  • Linux's thread local storage implementation

    - by anon
    __thread Foo foo; How is "foo" actually resolved? Does the compiler silently replace every instance of "foo" with a function call? Is "foo" stored somewhere relative to the bottom of the stack, and the compiler stores this as "hey, for each thread, have this space near the bottom of the stack, and foo is stored as 'offset x from bottom of stack'"?

    Read the article

  • Fast inter-thread communication mechanism

    - by Stan
    I need a fast inter-thread communication mechanism for passing work (void*) from TBB tasks to several workers which are running blocking operations. Currently I'm looking into using pipe()+libevent. Is there a faster and more elegant alternative for use with Intel Threading Building Blocks?

    Read the article

  • How do I write a analyzable thread dump format

    - by gamue
    I'm creating a global exception handling which collects some information before shutting down in some cases. One of this information is the current thread dump. i do this with following code: ManagementFactory.getThreadMXBean().dumpAllThreads(true, true); The problem is to write the information into a analyzable format for TDA. Is there a "simple" way to format the information instead of writing the format on my own?

    Read the article

  • How to debug hanging main thread in Delphi application

    - by Harriv
    Hi, I've written application in Delphi 2007, which some times hangs (not even every week, application is running 24/7). It looks like main thread gets stuck. What are the options to pinpoint the cause for this problem? Application is written in Delphi 2007, it uses RemObjects, DBExpress with Firebird, OPC communication using COM.

    Read the article

  • Is this ruby code thread safe?

    - by Ben K.
    Is this code threadsafe? It seems like it should be, because @myvar will never be assigned from multiple threads (assuming block completes in < 1s). But do I need to be worried about a situation where the second block is trying to read @myvar as it's being written? require 'rubygems' require 'eventmachine' @myvar = Time.now.to_i EventMachine.run do EventMachine.add_periodic_timer(1) do EventMachine.defer do @myvar = Time.now.to_i # some calculation and reassign end end EventMachine.add_periodic_timer(0.5) do puts @myvar end end

    Read the article

  • Run a form in another thread

    - by Smith
    i have five forms in my c# project. one host an httplistener that i want to run continionsly. when the listener gets a message, it passes it to a static class, which in turn calls the appropriate forms for another processing. is it possible that the static class calls the new form in a new thread? if so please help me out

    Read the article

  • C++ Thread level constants

    - by Gokul
    Is there a way by which we can simulate thread level constants in C++? For example, if i have to make a call to template functions, then i need to mention the constants as template level parameters? I can use static const variables for template metaprogramming, but they are process level constants. I know, i am asking a question with a high probability of 'No'. Just thought of asking this to capitalize on the very rare probability :)) Thanks, Gokul.

    Read the article

  • Problem with thread after SCREEN_OFF in Android

    - by michael
    I’m doing an application that listens to the android.intent.action.SCREEN_OFF in a Service (if that matter) and then it is supposed to wait a few seconds and launch an action, I’ve tried a timer schedule method, thread and handler postDelay method but all of them seems to fail, they are never executed on a device, it seems like it’s being freezed/killed after phone is locked. It works on emulator and on device attached to USB, but never with device working on battery only, which actually is a main scenario. Do you know any solutions to this?

    Read the article

  • ID generator with local static variable - thread-safe?

    - by Poseidon
    Will the following piece of code work as expected in a multi-threaded scenario? int getUniqueID() { static int ID=0; return ++ID; } It's not necessary that the IDs to be contiguous - even if it skips a value, it's fine. Can it be said that when this function returns, the value returned will be unique across all threads?

    Read the article

  • how a thread can signal when it's finished?

    - by Kyle
    #include <iostream> #include <boost/thread.hpp> using std::endl; using std::cout; using namespace boost; mutex running_mutex; struct dostuff { volatile bool running; dostuff() : running(true) {} void operator()(int x) { cout << "dostuff beginning " << x << endl; this_thread::sleep(posix_time::seconds(2)); cout << "dostuff is done doing stuff" << endl; mutex::scoped_lock running_lock(running_mutex); running = false; } }; bool is_running(dostuff& doer) { mutex::scoped_lock running_lock(running_mutex); return doer.running; } int main() { cout << "Begin.." << endl; dostuff doer; thread t(doer, 4); if (is_running(doer)) cout << "Cool, it's running.\n"; this_thread::sleep(posix_time::seconds(3)); if (!is_running(doer)) cout << "Cool, it's done now.\n"; else cout << "still running? why\n"; // This happens! :( return 0; } Why is the output of the above program: Begin.. Cool, it's running. dostuff beginning 4 dostuff is done doing stuff still running? why How can dostuff correctly flag when it is done? I do not want to sit around waiting for it, I just want to be notified when it's done.

    Read the article

  • Long running calculation on background thread

    - by SundayMonday
    In my Cocos2D game for iOS I have a relatively long running calculation that happens at a fairly regular interval (every 1-2 seconds). I'd like to run the calculation on a background thread so the main thread can keep the animation smooth. The calculation is done on a grid. Average grid size is about 100x100 where each cell stores an integer. Should I copy this grid when I pass it to the background thread? Or can I pass a reference and just make sure I don't write to the grid from the main thread before the background thread is done? Copying seems a bit wasteful but passing a reference seems risky. So I thought I'd ask.

    Read the article

  • Java - Call to start method on thread : how does it route to Runnable interface's run () ?

    - by Bhaskar
    Ok , I know the two standard ways to create a new thread and run it in Java : 1 Implement Runnable in a class , define run method ,and pass an instance of the class to a new Thread. When the start method on the thread instance is called , the run method of the class instance will be invoked. 2 Let the class derive from Thread, so it can to override the method run() and then when a new instance's start method is called , the call is routed to overridden method. In both methods , basically a new Thread object is created and its start method invoked. However , while in the second method , the mechanism of the call being routed to the user defined run() method is very clear ,( its a simple runtime polymorphism in play ), I dont understand how the call to start method on the Thread object gets routed to run() method of the class implementing Runnable interface. Does the Thread class have an private field of Type Runnable which it checks first , and if it is set then invokes the run method if it set to an object ? that would be a strange mechanism IMO. How does the call to start() on a thread get routed to the run method of the Runnable interface implemented by the class whose object is passed as a parameter when contructing the thread ?

    Read the article

  • Windows Form hangs when running threads

    - by Benjamin Ortuzar
    JI have written a .NET C# Windows Form app in Visual Studio 2008 that uses a Semaphore to run multiple jobs as threads when the Start button is pressed. It’s experiencing an issue where the Form goes into a comma after being run for 40 minutes or more. The log files indicate that the current jobs complete, it picks a new job from the list, and there it hangs. I have noticed that the Windows Form becomes unresponsive when this happens. The form is running in its own thread. This is a sample of the code I am using: protected void ProcessJobsWithStatus (Status status) { int maxJobThreads = Convert.ToInt32(ConfigurationManager.AppSettings["MaxJobThreads"]); Semaphore semaphore = new Semaphore(maxJobThreads, maxJobThreads); // Available=3; Capacity=3 int threadTimeOut = Convert.ToInt32(ConfigurationManager.AppSettings["ThreadSemaphoreWait"]);//in Seconds //gets a list of jobs from a DB Query. List<Job> jobList = jobQueue.GetJobsWithStatus(status); //we need to create a list of threads to check if they all have stopped. List<Thread> threadList = new List<Thread>(); if (jobList.Count > 0) { foreach (Job job in jobList) { logger.DebugFormat("Waiting green light for JobId: [{0}]", job.JobId.ToString()); if (!semaphore.WaitOne(threadTimeOut * 1000)) { logger.ErrorFormat("Semaphore Timeout. A thread did NOT complete in time[{0} seconds]. JobId: [{1}] will start", threadTimeOut, job.JobId.ToString()); } logger.DebugFormat("Acquired green light for JobId: [{0}]", job.JobId.ToString()); // Only N threads can get here at once job.semaphore = semaphore; ThreadStart threadStart = new ThreadStart(job.Process); Thread thread = new Thread(threadStart); thread.Name = job.JobId.ToString(); threadList.Add(thread); thread.Start(); } logger.Info("Waiting for all threads to complete"); //check that all threads have completed. foreach (Thread thread in threadList) { logger.DebugFormat("About to join thread(jobId): {0}", thread.Name); if (!thread.Join(threadTimeOut * 1000)) { logger.ErrorFormat("Thread did NOT complete in time[{0} seconds]. JobId: [{1}]", threadTimeOut, thread.Name); } else { logger.DebugFormat("Thread did complete in time. JobId: [{0}]", thread.Name); } } } logger.InfoFormat("Finished Processing Jobs in Queue with status [{0}]...", status); } //form methods private void button1_Click(object sender, EventArgs e) { buttonStop.Enabled = true; buttonStart.Enabled = false; ThreadStart threadStart = new ThreadStart(DoWork); workerThread = new Thread(threadStart); serviceStarted = true; workerThread.Start(); } private void DoWork() { EmailAlert emailAlert = new EmailAlert (); // start an endless loop; loop will abort only when "serviceStarted" flag = false while (serviceStarted) { emailAlert.ProcessJobsWithStatus(0); // yield if (serviceStarted) { Thread.Sleep(new TimeSpan(0, 0, 1)); } } // time to end the thread Thread.CurrentThread.Abort(); } //job.process() public void Process() { try { //sets the status, DateTimeStarted, and the processId this.UpdateStatus(Status.InProgress); //do something logger.Debug("Updating Status to [Completed]"); //hits, status,DateFinished this.UpdateStatus(Status.Completed); } catch (Exception e) { logger.Error("Exception: " + e.Message); this.UpdateStatus(Status.Error); } finally { logger.Debug("Relasing semaphore"); semaphore.Release(); } I have tried to log what I can into a file to detect where the problem is happening, but so far I haven't been able to identify where this happens. Losing control of the Windows Form makes me think that this has nothing to do with processing the jobs. Any ideas?

    Read the article

  • Cache consistency & spawning a thread

    - by Dave Keck
    Background I've been reading through various books and articles to learn about processor caches, cache consistency, and memory barriers in the context of concurrent execution. So far though, I have been unable to determine whether a common coding practice of mine is safe in the strictest sense. Assumptions The following pseudo-code is executed on a two-processor machine: int sharedVar = 0; myThread() { print(sharedVar); } main() { sharedVar = 1; spawnThread(myThread); sleep(-1); } main() executes on processor 1 (P1), while myThread() executes on P2. Initially, sharedVar exists in the caches of both P1 and P2 with the initial value of 0 (due to some "warm-up code" that isn't shown above.) Question Strictly speaking – preferably without assuming any particular CPU – is myThread() guaranteed to print 1? With my newfound knowledge of processor caches, it seems entirely possible that at the time of the print() statement, P2 may not have received the invalidation request for sharedVar caused by P1's assignment in main(). Therefore, it seems possible that myThread() could print 0. References These are the related articles and books I've been reading. (It wouldn't allow me to format these as links because I'm a new user - sorry.) Shared Memory Consistency Models: A Tutorial hpl.hp.com/techreports/Compaq-DEC/WRL-95-7.pdf Memory Barriers: a Hardware View for Software Hackers rdrop.com/users/paulmck/scalability/paper/whymb.2009.04.05a.pdf Linux Kernel Memory Barriers kernel.org/doc/Documentation/memory-barriers.txt Computer Architecture: A Quantitative Approach amazon.com/Computer-Architecture-Quantitative-Approach-4th/dp/0123704901/ref=dp_ob_title_bk

    Read the article

  • MMGR Questions, code use and thread-saftey

    - by chadb
    1) Is MMGR thread safe? 2) I was hoping someone could help me understand some code. I am looking at something where a macro is used, but I don't understand the macro. I know it contains a function call and an if check, however, the function is a void function. How does wrapping "(m_setOwner (FILE,_LINE_,FUNCTION),false)" ever change return types? #define someMacro (m_setOwner(__FILE__,__LINE__,__FUNCTION__),false) ? NULL : new ... void m_setOwner(const char *file, const unsigned int line, const char *func); 3) What is the point of the reservoir? 4) On line 770 ("void *operator new(size_t reportedSize)" there is the line "// ANSI says: allocation requests of 0 bytes will still return a valid value" Who/what is ANSI in this context? Do they mean the standards? 5) This is more of C++ standards, but where does "reportedSize" come from for "void *operator new(size_t reportedSize)"? 6) Is this the code that is actually doing the allocation needed? "au-actualAddress = malloc(au-actualSize);"

    Read the article

  • SAT Thread and Process output capture in c#

    - by alex
    Hi: This is a strange problem I encountered. I have an window application written in c# to do testing. It has a MDI parent form that is hosting a few children forms. One of the forms launch test cripts by creating processes and capture the scripts output to a text box. Another form open serial port and monitoring the status of the device I am working on(like a shell). If I ran both of them together, the output of the script seems only appear in the text box after the test is done. However, If I don't open the serial port form, the output of the script is captured in real time. Does anyone knows what's causing the problem? I notice the onDataReceived even handler for serial port form has a [SAThread] header to it. Will this cause the serial port thread having higher priority than other processes? Thanks in advance.

    Read the article

< Previous Page | 6 7 8 9 10 11 12 13 14 15 16 17  | Next Page >