Search Results

Search found 10004 results on 401 pages for 'thread pool'.

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

  • Unintentional run-in with C# thread concurrency

    - by geekrutherford
    For the first time today we began conducting load testing on a ASP.NET application already in production. Obviously you would normally want to load test prior to releasing to a production environment, but that isn't the point here.   We ran a test which simulated 5 users hitting the application doing the same actions simultaneously. The first few pages visited seemed fine and then things just hung for a while before the test failed. While the test was running I was viewing the performance counters on the server noting that the CPU was consistently pegged at 100% until the testing tool gave up.   Fortunately the application logs all exceptions including those unhandled to the database (thanks to log4net). I checked the log and low and behold the error was:   System.ArgumentException: An item with the same key has already been added. (The rest of the stack trace intentionally omitted)   Since the code was running with debug on the line number where the exception occured was also provided. I began inspecting the code and almost immediately it hit me, the section of code responsible for the exception is trying to initialize a static class. My next question was how is this code being hit multiple times when I have a rudimentary check already in place to prevent this kind of thing (i.e. a check on a public variable of the static class before entering the initializing routine). The answer...the check fails because the value is not set before other threads have already made it through.   Not being one who consistently works with threading I wasn't quite sure how to handle this problem. Fortunately a co-worker recalled having to lock a section of code in the past but couldn't recall exactly how. After a quick search on Google the solution is as follows:   Object objLock = new Object(); lock(objLock) { //logic requiring lock }   The lock statement takes an object and tells the .NET runtime that the current thread has exclusive access while the code within brackets is executing. Once the code completes, the lock is released for another thread to utilize.   In my case, I only need to execute the inner code once to initialize my static class. So within the brackets I have a check on a public variable to prevent it from being initialized again.

    Read the article

  • Use Thread-local Storage to Reduce Synchronization

    Synchronization is often an expensive operation that can limit the performance of a multithreaded program. Using thread-local data structures instead of data structures shared by the threads can reduce synchronization in certain cases, allowing a program to run faster.

    Read the article

  • [Java] - Problem having my main thread sleeping

    - by Chris
    I'm in a Java class and our assignment is to let us explore threads in Java. So far so good except for this one this one problem. And I believe that could be because of my lack of understanding how Java threads work at the moment. I have the main thread of execution which spawns new threads. In the main thread of execution in main() I am calling Thread.sleep(). When I do I get an Unhandled exception type InterruptedException. I am unsure of why I am getting this? I thought this was because I needed a reference to the main thread so I went ahead and made a reference to it via Thread.currentThread(). Is this not the way to have the thread sleep? What I need to do is have the main thread wait/sleep/delay till it does it required work again. Any help would be much appreciated.

    Read the article

  • Thread Local Storage and local method variables

    - by miguel
    In c#, each thread has its own stack space. If this is the case, why is the following code not thread-safe? (It is stated that this code is thread-safe on this post: Locking in C# class Foo { private int count = 0; public void TrySomething() { count++; } } As count is an int (stack variable), surely this value would be isolated to an individual thread, on its own stack, and therefore thread-safe? I am probably missing something here, but I dont understand what is actually in Thread Local Storage if not stack-based variables for the thread?

    Read the article

  • How to correctly stop thread which is using Control.Invoke

    - by codymanix
    I tried the following (pseudocode) but I always get a deadlock when Iam trying to stop my thread. The problem is that Join() waits for the thread to complete and a pending Invoke() operation is also waiting to complete. How can I solve this? Thread workerThread = new Thread(BackupThreadRunner); volatile bool cancel; // this is the thread worker routine void BackupThreadRunner() { while (!cancel) { DoStuff(); ReportProgress(); } } // main thread void ReportProgress() { if (InvokeRequired) { Invoke(ReportProgress); } UpdateStatusBarAndStuff(); } // main thread void DoCancel() { cancel=true; workerThread.Join(); }

    Read the article

  • Java: serial thread confinement question

    - by denis
    Assume you have a Collection(ConcurrentLinkedQueue) of Runnables with mutable state. Thread A iterates over the Collection and hands the Runnables to an ExecutorService. The run() method changes the Runnables state. The Runnable has no internal synchronization. The above is a repetitive action and the worker threads need to see the changes made by previous iterations. So a Runnable gets processed by one worker thread after another, but is never accessed by more than one thread at a time - a case of serial thread confinement(i hope ;)). The question: Will it work just with the internal synchronization of the ConcurrentLinkedQueue/ExecutorSerivce? To be more precise: If Thread A hands Runnable R to worker thread B and B changes the state of R, and then A hands R to worker thread C..does C see the modifications done by B?

    Read the article

  • c style thread creation in python

    - by chandank
    Hi I am new to python and want to create multiple threads in a loop something like (in C style) for (;i < 10; i++) thread[i]= pthread_create(&thread[i],&attr,func) I am not sure how to do the same in python? Basically I want have that thread[] variable as global will create all thread at once and then will start then in once. I have written a similar python program that does it but I think having it in above style will be better. def thread_create(thread_number): command_string = "Thread-" + "%d" %thread_number thread = myThread(thread_number, command_string) thread.start() # Start new Threads for i in range(5): thread_create(i)

    Read the article

  • Java Thread Message Passing

    - by pkulak
    I'm writing an Android app. I have a main method, which creates and runs a new Thread using an anonymous inner Runnable class. The run() method, when it's done, calls a method on it's parent class (in the main thread) that calls notifyDataSetChanged() so that the main thread can redraw the new data. This is causing all kinds of trouble (ViewRoot$CalledFromWrongThreadException). The thing is, this method being called from the worker thread is on the class that's created in the UI thread. Shouldn't that be running on the UI thread? Or am I missing something? Here's some code about what I'm talking about: public class Mealfire extends Activity { @Override public void onCreate(Bundle icicle) { (new Thread() { public void run() { // Do a bunch of slow network stuff. update(); } }).start(); } private void update() { myAdapter.notifyDatasetChanged(); } }

    Read the article

  • Turn based synchronization between threads

    - by Amarus
    I'm trying to find a way to synchronize multiple threads having the following conditions: * There are two types of threads: 1. A single "cyclic" thread executing an infinite loop to do cyclic calculations 2. Multiple short-lived threads not started by the main thread * The cyclic thread has a sleep duration between each cycle/loop iteration * The other threads are allowed execute during the inter-cycle sleep of the cyclic thread: - Any other thread that attempts to execute during an active cycle should be blocked - The cyclic thread will wait until all other threads that are already executing to be finished Here's a basic example of what I was thinking of doing: // Somewhere in the code: ManualResetEvent manualResetEvent = new ManualResetEvent(true); // Allow Externally call CountdownEvent countdownEvent = new CountdownEvent(1); // Can't AddCount a CountdownEvent with CurrentCount = 0 void ExternallyCalled() { manualResetEvent.WaitOne(); // Wait until CyclicCalculations is having its beauty sleep countdownEvent.AddCount(); // Notify CyclicCalculations that it should wait for this method call to finish before starting the next cycle Thread.Sleep(1000); // TODO: Replace with actual method logic countdownEvent.Signal(); // Notify CyclicCalculations that this call is finished } void CyclicCalculations() { while (!stopCyclicCalculations) { manualResetEvent.Reset(); // Block all incoming calls to ExternallyCalled from this point forward countdownEvent.Signal(); // Dirty workaround for the issue with AddCount and CurrentCount = 0 countdownEvent.Wait(); // Wait until all of the already executing calls to ExternallyCalled are finished countdownEvent.Reset(); // Reset the CountdownEvent for next cycle. Thread.Sleep(2000); // TODO: Replace with actual method logic manualResetEvent.Set(); // Unblock all threads executing ExternallyCalled Thread.Sleep(1000); // Inter-cycles delay } } Obviously, this doesn't work. There's no guarantee that there won't be any threads executing ExternallyCalled that are in between manualResetEvent.WaitOne(); and countdownEvent.AddCount(); at the time the main thread gets released by the CountdownEvent. I can't figure out a simple way of doing what I'm after, and almost everything that I've found after a lengthy search is related to producer/consumer synchronization which I can't apply here.

    Read the article

  • Call an AsyncTask inside a Thread

    - by Arun
    I am working in an android application and I want to call an AsyncTask from my UI main thread. For that I want to call my AsyncTask from a thread. This is the method that I call from my main UI thread. This is working correctly CommonAysnk mobjCommonAysnk = new CommonAysnk(this, 1); mobjCommonAysnk.execute(); CommonAysnk is my AsyncTask class.I want to pass my activity and an integer parameter to the AsyncTask constructor. How can I call this from a thread as shown below method. Thread t = new Thread() { public void run() { try { CommonAysnk mobjCommonAysnk = new CommonAysnk(this, 1); mobjCommonAysnk.execute(); } catch (Exception ex) { }}}; t.start(); When I tried to call it from a Thread and I am not able to pass the activity parameter correctly. How can we sole this. Thanks

    Read the article

  • Does SetThreadPriority cause thread reschedulling?

    - by Suma
    Consider following situation, assuming single CPU system: thread A is running with a priority THREAD_PRIORITY_NORMAL, signals event E thread B with a priority THREAD_PRIORITY_LOWEST is waiting for an event E (Note: at this point the thread is not scheduled because it is runnable, but A is higher priority and runnable as well) thread A calls SetThreadPriority(B, THREAD_PRIORITY_ABOVE_NORMAL) Is thread B re-scheduled immediately to run, or is thread A allowed to continue until current time-slice is over, and B is scheduled only once a new time-slice has begun? I would be interested to know the answer for WinXP, Vista and Win7, if possible. Note: the scenario above is simplified from my real world code, where multiple threads are running on multiple cores, but the main object of the question stays: does SetThreadPriority cause thread scheduling to happen?

    Read the article

  • Memory leak at Autorelease pool in Iphone sdk

    - by monish
    Hi guys, I am getting leak at [pool release]; My code here is: #pragma mark UISearchBarDelegate delegate methods - (void)performSearch:(UISearchBar *)aSearchBar { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; artistName= [aSearchBar.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; if ([artistName length] > 0) { [UIApplication sharedApplication].networkActivityIndicatorVisible = YES; LyricsAppDelegate* appDelegate = (LyricsAppDelegate*) [ [UIApplication sharedApplication] delegate]; artistsList=[appDelegate doSearch:artistName ]; [theTableView reloadData]; [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; [aSearchBar resignFirstResponder]; } else { [aSearchBar resignFirstResponder]; } [NSThread exit]; [pool release]; } - (void)searchBarSearchButtonClicked:(UISearchBar *)aSearchBar { @try { [NSThread detachNewThreadSelector:@selector(performSearch:) toTarget:self withObject:aSearchBar]; [aSearchBar resignFirstResponder]; } @catch (NSException * e) { NSLog(@"\n caught an exception"); } @finally { } } Here I am getting leak at [pool release]; in performSearch method. How can I solve this. Anyone's help will be much appreciated. Thank you, Monish.

    Read the article

  • All connections in pool are in use

    - by veljkoz
    We currently have a little situation on our hands - it seems that someone, somewhere forgot to close the connection in code. Result is that the pool of connections is relatively quickly exhausted. As a temporary patch we added Max Pool Size = 500; to our connection string on web service, and recycle pool when all connections are spent, until we figure this out. So far we have done this: SELECT SPId FROM MASTER..SysProcesses WHERE DBId = DB_ID('MyDb') and last_batch < DATEADD(MINUTE, -15, GETDATE()) to get SPID's that aren't used for 15 minutes. We're now trying to get the query that was executed last using that SPID with: DBCC INPUTBUFFER(61) but the queries displayed are various, meaning either something on base level regarding connection manipulation was broken, or our deduction is erroneous... Is there an error in our thinking here? Does the DBCC / sysprocesses give results we're expecting or is there some side-effect catch? (for example, connections in pool influence?) (please, stick to what we could find out using SQL since the guys that did the code are many and not all present right now)

    Read the article

  • C++ Simple thread with parameter (no .net)

    - by Marc Vollmer
    I've searched the internet for a while now and found different solutions but then all don't really work or are to complicated for my use. I used C++ until 2 years ago so it might be a bit rusty :D I'm currently writing a program that posts data to an URL. It only posts the data nothing else. For posting the data I use curl, but it blocks the main thread and while the first post is still running there will be a second post that should start. In the end there are about 5-6 post operations running at the same time. Now I want to push the posting with curl into another thread. One thread per post. The thread should get a string parameter with the content what to push. I'm currently stuck on this. Tried the WINAPI for windows but that crashes on reading the parameter. (the second thread is still running in my example while the main thread ended (waiting on system("pause")). It would be nice to have a multi plattform solution, because it will run under windows and linux! Heres my current code: #define CURL_STATICLIB #include <curl/curl.h> #include <curl/easy.h> #include <cstdlib> #include <iostream> #include <stdio.h> #include <stdlib.h> #include <string> #if defined(WIN32) #include <windows.h> #else //#include <pthread.h> #endif using namespace std; void post(string post) { // Function to post it to url CURL *curl; // curl object CURLcode res; // CURLcode object curl = curl_easy_init(); // init curl if(curl) { // is curl init curl_easy_setopt(curl, CURLOPT_URL, "http://10.8.27.101/api.aspx"); // set url string data = "api=" + post; // concat post data strings curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data.c_str()); // post data res = curl_easy_perform(curl); // execute curl_easy_cleanup(curl); // cleanup } else { cerr << "Failed to create curl handle!\n"; } } #if defined(WIN32) DWORD WINAPI thread(LPVOID data) { // WINAPI Thread string pData = *((string*)data); // convert LPVOID to string [THIS FAILES] post(pData); // post it with curl } #else // Linux version #endif void startThread(string data) { // FUnction to start the thread string pData = data; // some Test #if defined(WIN32) CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)thread, &pData, 0, NULL); // Start a Windows thread with winapi #else // Linux version #endif } int main(int argc, char *argv[]) { // The post data to send string postData = "test1234567890"; startThread(postData); // Start the thread system("PAUSE"); // Dont close the console window return EXIT_SUCCESS; } Has anyone a suggestion? Thanks for the help!

    Read the article

  • IUSR vs. Application Pool credentials

    - by jlew
    I have a IIS7/ASP.NET application running with the following configuration: Anonymous authentication (IUSR). Application Pool running as a domain account If IUSR is denied the "logon locally", then it appears that ASPX pages will still render their HTML, but static content such as images will not be delivered. I'm wondering what the technical reason is for this? If IUSR is "broken", why will a request to an ASPX page be passed down the pipeline and executed, but IIS will refuse to serve an image in the same directory?

    Read the article

  • Alternative to application pool startMode="AlwaysRunning"

    - by Chris Marisic
    If a web application called for itself to be setup with it's application pool to be configured in the applicationHost.config as: <add name="AppPool" managedRuntimeVersion="v4.0" startMode="AlwaysRunning" /> Would the same result be achieved by just requesting a page from the server every minute? Or does setting startMode to this value have other implications also?

    Read the article

  • Resource Pool sharing in Hyper-V Virtual Machines

    - by user67905
    I understand that we can install Hyper-V on one server and run a number of Virtual Machines on it, upto the limit of resources of that server. I want to know if it is possible to install Hyper-V lumped on two or more servers, so that the Virtual Machines can use the underlying resources pool of both the servers? And also if that same is possible for an “n” number of servers, instead of just 2 servers.

    Read the article

  • safely remove webserver from nginx backent pool?

    - by Dean Hiller
    We have 4 webservers behind nginx being hit with 262 events/second. I would like to tell nginx to stop sending requests to that server. If I remove the server from the file and reload the file, aren't all requests in process dropped on the floor then as nginx no longer knows that server. What can I add to the config so it slowly drops that server out of the pool and I can wait for current requests to complete.

    Read the article

  • Connection Pool error LINQ to SQL

    - by Ved
    Guys, In Our project I have used LINQ to SQL for every kind of database interaction. Now from what I know , When I create and use DataContext object : it opens the connection , crates a transaction , perform the query and closes the connection. Every now and then we are getting Connection pool error on our services and Server. " The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached. " Any idea ? Am I completely off here ? Is this related to SQL Server itself ? We are using LINQ , .Net 3.5 and Sql Server 2008 NOTE: NO DATAREADER IS BEING USED ANYWHERE IN SYSTEM. Thanks

    Read the article

  • Stop IIS 7 Application Pool from build script

    - by Andrew Hanson
    How can I stop and then restart an IIS 7 application pool from an MSBuild script running inside TeamCity. I want to deploy our nightly builds to an IIS server for out testers to view. I have tried using appcmd like so: appcmd stop apppool /apppool.name:MYAPP-POOL ... but I have run into elevation issues in Windows 2008 that so far have stopped me from being able to run that command from my TeamCity build process because Windows 2008 requires elevation in order to run appcmd. If I do not stop the application pool before I copy my files to the web server my MSBuild script is unable to copy the files to the server. Has anybody else seen and solved this issue when deploying web sites to IIS from TeamCity?

    Read the article

  • How to deal with OpenMP thread pool contention

    - by dpe82
    I'm working on an application that uses both coarse and fine grained multi-threading. That is, we manage scheduling of large work units on a pool of threads manually, and then within those work units certain functions utilize OpenMP for finer grain multithreading. We have realized gains by selectively using OpenMP in our costliest loops, but are concerned about creating contention for the OpenMP worker pool as we add OpenMP blocks to cheaper loops. Is there a way to signal to OpenMP that a block of code should use the pool if it is available, and if not it should process the loop serially?

    Read the article

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