Search Results

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

Page 3/66 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Google Javascript v8 - multithreading

    - by willem
    Hi guys Suppose I have the following piece of code bool run (void) { HandleScope hande_scope; Handle<String> source; Local<Script> script; Persistent<Context> context; context = Context::New(); Context::Scope context_scope(context); script = Script::Compile("var a = 1; var b = 2;"); Local<Value> result = script->Run(); if (result.IsEmpty()) return false; else return true; } Is it true that one cannot execute this code using multiple threads? It seems like HandleScope is not designed to be used in multithreaded applications. I can use the v8::Locker and v8::Unlocker methodes but that would always give me execution traces as this: t1: a = 1 t1: b = 2 t2: a = 1 t2: b = 2 I hope someone can give me a hint on getting this code multithreaded so that a possible execution trace could like this: t1: a = 1 t2: a = 1 t1: b = 2 t2: b = 2 Thanks already in advance! Willem -- EDIT -- So I guess that this question has no answer :)

    Read the article

  • SQLite on iPhone - Techniques for tracking down multithreading-related bugs

    - by Jasarien
    Hey guys, I'm working with an Objective-C wrapper around SQLite that I didn't write, and documentation is sparse... It's not FMDB. The people writing this wrapper weren't aware of FMDB when writing this code. It seems that the code is suffering from a bug where database connections are being accessed from multiple threads -- which according to the SQLite documentation won't work if the if SQLite is compiled with SQLITE_THREADSAFE 2. I have tested the libsqlite3.dylib provided as part of the iPhone SDK and seen that it is compiled in this manner, using the sqlite_threadsafe() routine. Using the provided sqlite library, the code regularly hits SQLITE_BUSY and SQLITE_LOCKED return codes when performing routines. To combat this, I added some code to wait a couple of milliseconds and try again, with a maximum retry count of 50. The code didn't contain any retry logic prior to this. Now when a sqlite call returns SQLITE_BUSY or SQLITE_LOCKED, the retry loop is invoked and the retry returns SQLITE_MISUSE. Not good. Grasping at straws, I replaced the provided sqlite library with a version compiled by myself setting SQLITE_THREADSAFE to 1 - which according to the documentation means sqlite is safe to be used in a multithreaded environment, effectively serialising all of the operations. It incurs a performance hit, that which I haven't measured, but it ridded the app of the SQLITE_MISUSE happening and seemed to not need the retry logic as it never hit a busy or locked state. What I would rather do is fix the problem of accessing a single db connection from multiple threads, but I can't for the life of me find where it's occurring. So if anyone has any tips on locating multithreaded bugs I would be extremely appreciative. Thanks in advance.

    Read the article

  • How to demonstrate java multithreading visibility problems?

    - by Joe23
    If variables in Java are accessed from multiple threads, one must ensure that they are safely published. This usually means using synchronizedor volatile. I have got the impression, that some of my colleagues do not take this issue seriously, since they "never heard of volatile before and their programs have worked for years". So my question is: Can someone provide an example Java program/snippet, that reliably shows data visibility problems. I think running a program and seeing the unexpected NPE or stale variable value would help more, than just theoretic explanations, that cannot be demonstrated. Thanks a lot for your help!

    Read the article

  • C++ Multithreading with pthread is blocking (including sockets)

    - by Sebastian Büttner
    I am trying to implement a multi threaded application with pthread. I did implement a thread class which looks like the following and I call it later twice (or even more), but it seems to block instead of execute the threads parallel. Here is what I got until now: The Thread Class is an abstract class which has the abstract method "exec" which should contain the thread code in a derive class (I did a sample of this, named DerivedThread) Thread.hpp #ifndef THREAD_H_ #define THREAD_H_ #include <pthread.h> class Thread { public: Thread(); void start(); void join(); virtual int exec() = 0; int exit_code(); private: static void* thread_router(void* arg); void exec_thread(); pthread_t pth_; int code_; }; #endif /* THREAD_H_ */ And Thread.cpp #include <iostream> #include "Thread.hpp" /*****************************/ using namespace std; Thread::Thread(): code_(0) { cout << "[Thread] Init" << endl; } void Thread::start() { cout << "[Thread] Created Thread" << endl; pthread_create( &pth_, NULL, Thread::thread_router, reinterpret_cast<void*>(this)); } void Thread::join() { cout << "[Thread] Join Thread" << endl; pthread_join(pth_, NULL); } int Thread::exit_code() { return code_; } void Thread::exec_thread() { cout << "[Thread] Execute" << endl; code_ = exec(); } void* Thread::thread_router(void* arg) { cout << "[Thread] exec_thread function in thread" << endl; reinterpret_cast<Thread*>(arg)->exec_thread(); return NULL; } DerivedThread.hpp #include "Thread.hpp" class DerivedThread : public Thread { public: DerivedThread(); virtual ~DerivedThread(); int exec(); void Close() = 0; DerivedThread.cpp [...] #include "DerivedThread.cpp" [...] int DerivedThread::exec() { //code to be executed do { cout << "Thread executed" << endl; usleep(1000000); } while (true); //dummy, just to let it run for a while } [...] Basically, I am calling this like the here: DerivedThread *thread; cout << "Creating Thread" << endl; thread = new DerivedThread(); cout << "Created thread, starting..." << endl; thread->start(); cout << "Started thread" << endl; cout << "Creating 2nd Thread" << endl; thread = new DerivedThread(); cout << "Created 2nd thread, starting..." << endl; thread->start(); cout << "Started 2nd thread" << endl; What is working great if I am only starting one of these Threads , but if I start multiple which should run together (not synced, only parallel) . But I discovered, that the thread is created, then as it tries to execute it (via start) the problem seems to block until the thread has closed. After that the next Thread is processed. I thought that pthread would do it unblocked for me, so what did I wrong? A sample output might be: Creating Thread [Thread] Thread Init Created thread, starting... [Thread] Created thread [Thread] exec_thread function in thread [Thread] Execute Thread executed Thread executed Thread executed Thread executed Thread executed Thread executed Thread executed .... Until Thread 1 is not terminated, a Thread 2 won't be created not executed. The process above is executed in an other class. Just for the information: I am trying to create a multi threaded server. The concept is like this: MultiThreadedServer Class has a main loop, like this one: ::inet::ServerSock *sock; //just a simple self made wrapper class for sockets DerivedThread *thread; for (;;) { sock = new ::inet::ServerSock(); this->Socket->accept( *sock ); cout << "Creating Thread" << endl; //Threads (according to code sample above) thread = new DerivedThread(sock); //I did not mentoine the parameter before as it was not neccesary, in fact, I pass the socket handle with the connected socket to the thread cout << "Created thread, starting..." << endl; thread->start(); cout << "Started thread" << endl; } So I thought that this would loop over and over and wait for new connections to accept. and when a new client arrives, I am creating a new thread and give the thread the connected socket as a parameter. In the DerivedThread::exec I am doing the handling for the connected client. Like: [...] do { [...] if (this-sock_-read( Buffer, sizeof(PacketStruc) ) 0) { cout << "[Handler_Base] Recv Packet" << endl; //handle the packet } else { Connected = false; } delete Buffer; } while ( Connected ); So I loop in the created thread as long as the client keeps the connection. I think, that the socket may cause the blocking behaviour. Edit: I figured out, that it is not the read() loop in the DerivedThread Class as I simply replaced it with a loop over a simple cout-usleep part. It did also only execute the first one and after first thread finished, the 2nd one was executed. Many thanks and best regards, Sebastian

    Read the article

  • Multithreading in .NET 4

    - by Artiom Chilaru
    I have heard that the .NET 4 team has added new classes in the framework that make working with threads better and easier. Basically the question is what are the new ways to run multithreaded tasks added in .NET 4 and what are they designed to be used for?

    Read the article

  • Multithreading in Lua

    - by RCIX
    I was having a discussion with my friend the other day. I was saying how that, in pure Lua, you couldn't build a preemptive multitasking system. He claims you can, because of the following reason: Both C and Lua have no inbuilt threading libraries [OP's note: well, Lua technically does, but AFAIK it's not useful for our purposes]. Windows, which is written in mostly C(++) has pre-emptive multitasking, which they built from scratch. Therefore, you should be able to do the same in Lua. The big problem i see with that is that the main way preemptive multitasking works (to my knowledge) is that it generates regular interrupts which the manager uses to get control and determine what code it should be working on next. I also don't think Lua has any facility that can do that. My question is: is it possible to write a pure-Lua library that allows people to have pre-emptive multitasking?

    Read the article

  • python multithreading for dummies

    - by albruno
    trying to find a simple example that clearly shows a single task being divided for multi-threading. Quite frankly... many of the examples are overly sophisticated thus.... making the flow tougher to play with... anyone care to share their breakthrough sample or point to an example? As well, what is the best docs? many google lookups are too specific (for me at this stage) Thanks in advance.

    Read the article

  • multithreading issue

    - by vbNewbie
    I have written a multithreaded crawler and the process is simply creating threads and having them access a list of urls to crawl. They then access the urls and parse the html content. All this seems to work fine. Now when I need to write to tables in a database is when I experience issues. I have 2 declared arraylists that will contain the content each thread parse. The first arraylist is simply the rss feed links and the other arraylist contains the different posts. I then use a for each loop to iterate one while sequentially incrementing the other and writing to the database. My problem is that each time a new thread accesses one of the lists the content is changed and this affects the iteration. I tried using nested loops but it did not work before and this works fine using a single thread.I hope this makes sense. Here is my code: SyncLock dlock For Each l As String In links finallinks.Add(l) Next End SyncLock SyncLock dlock For Each p As String In posts finalposts.Add(p) Next End SyncLock ... Dim i As Integer = 0 SyncLock dlock For Each rsslink As String In finallinks postlink = finalposts.Item(i) i = i + 1 finallinks and finalposts are the two arraylists. I did not include the rest of the code which shows the threads working but this is the essential part where my error occurs which is basically here postlink = finalposts.Item(i) i = i + 1 ERROR: index was out of range. Must be non-negative and less than the size of the collection Is there an alternative?

    Read the article

  • Ruby Multithreading: making one thread wait for a signal from another

    - by Peter
    In Ruby, I want to have two threads running at the same time, and want the background thread to periodically signal the foreground thread. How do I get the foreground thread to block until the background thread says 'go'? I can think of a few ways to do it, but am after the most appropriate, idiomatic Ruby method. In code: loop do # background, thread 1 sleep 3 receive_input # tell foreground input is ready # <-- how do I do this? end and loop do # foreground, thread 2 wait_for_signal_from_background # <-- how do I do this? do_something end

    Read the article

  • Multithreading Errors in C#

    - by Adam
    Hi. I am trying to update a text box. I thought my threading code would fix the problem, but it does not. Can anyone help with this? new Thread((ThreadStart)delegate { txtCapacitance.Text = Math.Round(capacitance, 3).ToString(); }).Start(); Gives the following error: Cross-thread operation not valid: Control 'txtCapacitance' accessed from a thread other than the thread it was created on. Note that all this is being started by a dataReceived function which is called whenever USB data is received.

    Read the article

  • How does Java handle multithreading?

    - by badcodenotreat
    How does Java decide which core to assign a thread or a process? Is there any way to control that? to prevent two large threads from executing on the same core? Basically what I am asking is for further information on either how multi-threading works in Java, or how to control it within Java.

    Read the article

  • c multithreading

    - by coubeatczech
    hi, there's a weird behaviour in my threads: void * foo(void * nic){ printf("foo"); } void * threadF(void * ukazatel){ printf("1\n"); pthread_t threadT; pthread_attr_t attr; pthread_attr_init (&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); pthread_create(&threadT,NULL,&foo,(void*)NULL); printf("2\n"); while (!feof(stdin)){ int id, in, out; fscanf(stdin,"%d:%d:%d",&id,&in,&out); } } int main(){ pthread_attr_t attr; pthread_attr_init (&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); pthread_t threadT; pthread_create(&vlaknoVstupu,&attr,&threadF,(void*)&data); pthread_join(threadT,NULL); pthread_attr_destroy (&attr); } // I skipped irelevant parts of code... the thing is, that sometimes, the output is 12foo, but usually just 12. Then the function waits for input. I would expect it to be always 12foo. Do anybody know why are my expectations wrong?

    Read the article

  • C# WinForms MultiThreading in Loop

    - by Goober
    Scenario I have a background worker in my application that runs off and does a bunch of processing. I specifically used this implementation so as to keep my User Interface fluid and prevent it from freezing up. I want to keep the background worker, but inside that thread, spawn off ONLY 3 MORE threads - making them share the processing (currently the worker thread just loops through and processes each asset one-by-one. However I would like to speed this up but using only a limited number of threads. Question Given the code below, how can I get the loop to choose a thread that is free, and then essentially wait if there isn't one free before it continues. CODE foreach (KeyValuePair<int, LiveAsset> kvp in laToHaganise) { Haganise h = new Haganise(kvp.Value, busDate, inputMktSet, outputMktSet, prodType, noOfAssets, bulkSaving); h.DoWork(); } Thoughts I'm guessing that I would have to start off by creating 3 new threads, but my concern is that if I'm instantiating a new Haganise object each time - how can I pass the correct "h" object to the correct thread..... Thread firstThread = new Thread(new ThreadStart(h.DoWork)); Thread secondThread =new Thread(new ThreadStart(h.DoWork)); Thread thirdThread = new Thread(new ThreadStart(h.DoWork)); Help greatly appreciated.

    Read the article

  • Should I Solve this with Multithreading in Ruby?

    - by viatropos
    I have a strange case, here's the sequence of actions: User edits a document and hits save Application sends GET request to service Service sends POST request back to application in the middle of responding to the GET request Application, in the same state as when it made the GET request, responds to the POST request (sends document data) to service. Service sends data back to Application (responding to original GET request) Application handles the rest... The use case is this: I was thinking how can I make Yahoo Pipes POST data? Specifically, I want it to be able to update Google Docs when a user makes a change locally (on a custom editor). So user edits doc, makes GET request to Yahoo Pipes, Pipes makes a POST request back to App to get the document (Pipes can only make this type of POST request), App sends doc, Pipes formats data according to the Google API, Pipes responds to GET request with Google API formatted XML, App makes the post request. Theoretically, how would I accomplish this? It seems that I need to create a separate ruby Process for the GET request, and when Pipes sends the POST request, I find that process and send its output, then I'm stuck. This would cut out the need for a database for this particular case (I could save the stuff temporarily in a database, but that doesn't seem right). Any ideas? This would make it so I don't have to format things to the Google API in ruby, I could leave that to Pipes.

    Read the article

  • tomcat multithreading problem

    - by jutky
    Hi all I'm writing a java application that runs in Tomcat, on a multi-core hardware. The application executes an algorithm and returns the answer to the user. The problem is that even when I run two requests simultaneously, the tomcat process uses at most one CPU core. As far as I understand each request in Tomcat is executed in separate thread, and JVM should run each thread on separate CPU core. What could be the problem that bounds the JVM or Tomcat to use no more than one core? Thanks in advance.

    Read the article

  • Windows 7 versus Windows XP multithreading - Delphi app not acting right

    - by Robert Oschler
    I'm having a problem with a Delphi Pro 6 application that I wrote on my Windows XP machine when it runs on Windows 7. I don't have Windows 7 to test yet and I'm trying to see if Windows 7 might be the source of the trouble. Is there a fundamental difference between the way Windows 7 handles threads compared to Windows XP? I am seeing things happen out of sequence in my error logs on Windows 7 and it's causing problems. For example, objects that should have been initialized are uninitialized when running on Windows 7, yet those objects are initialized on Windows XP by the time they are needed. Some questions: 1) Are there any core differences that could cause threads/processes to behave differently between the two operating system versions? 2) I know this next question may seem absurd, but does Windows 7 attempt to split/fork threads that aren't split/forked on Windows XP? 3) And lastly, are there any known issues with FPU handling that can cause XP programs trouble when run on Windows 7 due to operational differences in wait state handling or register storage, or perhaps something like Exception mask settings, etc? 4) Any 32-bit versus 64-bit issues that could be creating trouble here? -- roschler

    Read the article

  • Android Multithreading, creating new thread not executing rest of OnCreate

    - by Aidan
    Hi Guys, Basically I'm trying to run 2 threads within the same class at the same time. The code runs but only executes whats in run() and doesnt finish the onCreate method... anyone know why? public Camera1(){ t = new Thread(this, "My Thread"); t.start(); } public void run(){ bearing(); } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); new Camera1(); makeview(); tracking(); } Thanks!

    Read the article

  • For loop index out of range ArgumentOutOfRangeException when multithreading

    - by Lirik
    I'm getting some strange behavior... when I iterate over the dummyText List in the ThreadTest method I get an index out of range exception (ArgumentOutOfRangeException), but if I remove the threads and I just print out the text, then everything works fine. This is my main method: public static Object sync = new Object(); static void Main(string[] args) { ThreadTest(); Console.WriteLine("Press any key to continue."); Console.ReadKey(); } This method throws the exception: private static void ThreadTest() { Console.WriteLine("Running ThreadTest"); Console.WriteLine("Running ThreadTest"); List<String> dummyText = new List<string>() { "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten"}; for (int i = 0; i < dummyText.Count; i++) { Thread t = new Thread(() => PrintThreadName(dummyText[i])); // <-- Index out of range?!? t.Name = ("Thread " + (i)); t.IsBackground = true; t.Start(); } } private static void PrintThreadName(String text) { Random rand = new Random(DateTime.Now.Millisecond); while (true) { lock (sync) { Console.WriteLine(Thread.CurrentThread.Name + " running " + text); Thread.Sleep(1000+rand.Next(0,2000)); } } } This does not throw the exception: private static void ThreadTest() { Console.WriteLine("Running ThreadTest"); List<String> dummyText = new List<string>() { "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten"}; for (int i = 0; i < dummyText.Count; i++) { Console.WriteLine(dummyText[i]); // <-- No exception here } } Does anybody know why this is happening?

    Read the article

  • Improve heavy work in a loop in multithreading

    - by xjaphx
    I have a little problem with my data processing. public void ParseDetails() { for (int i = 0; i < mListAppInfo.Count; ++i) { ParseOneDetail(i); } } For 300 records, it usually takes around 13-15 minutes. I've tried to improve by using Parallel.For() but it always stop at some point. public void ParseDetails() { Parallel.For(0, mListAppInfo.Count, i => ParseOneDetail(i)); } In method ParseOneDetail(int index), I set an output log for tracking the record id which is under processing. Always hang at some point, I don't know why.. ParseOneDetail(): 89 ... ParseOneDetail(): 90 ... ParseOneDetail(): 243 ... ParseOneDetail(): 92 ... ParseOneDetail(): 244 ... ParseOneDetail(): 93 ... ParseOneDetail(): 245 ... ParseOneDetail(): 247 ... ParseOneDetail(): 94 ... ParseOneDetail(): 248 ... ParseOneDetail(): 95 ... ParseOneDetail(): 99 ... ParseOneDetail(): 249 ... ParseOneDetail(): 100 ... _ <hang at this point> Appreciate your help and suggestions to improve this. Thank you! Edit 1: update for method: private void ParseOneDetail(int index) { Console.WriteLine("ParseOneDetail(): " + index + " ... "); ApplicationInfo appInfo = mListAppInfo[index]; var htmlWeb = new HtmlWeb(); var document = htmlWeb.Load(appInfo.AppAnnieURL); // get first one only HtmlNode nodeStoreURL = document.DocumentNode.SelectSingleNode(Constants.XPATH_FIRST); appInfo.StoreURL = nodeStoreURL.Attributes[Constants.HREF].Value; } Edit 2: This is the error output after a while running as Enigmativity suggest, ParseOneDetail(): 234 ... ParseOneDetail(): 87 ... ParseOneDetail(): 235 ... ParseOneDetail(): 236 ... ParseOneDetail(): 88 ... ParseOneDetail(): 238 ... ParseOneDetail(): 89 ... ParseOneDetail(): 90 ... ParseOneDetail(): 239 ... ParseOneDetail(): 92 ... Unhandled Exception: System.AggregateException: One or more errors occurred. --- > System.Net.WebException: The operation has timed out at System.Net.HttpWebRequest.GetResponse() at HtmlAgilityPack.HtmlWeb.Get(Uri uri, String method, String path, HtmlDocum ent doc, IWebProxy proxy, ICredentials creds) in D:\Source\htmlagilitypack.new\T runk\HtmlAgilityPack\HtmlWeb.cs:line 1355 at HtmlAgilityPack.HtmlWeb.LoadUrl(Uri uri, String method, WebProxy proxy, Ne tworkCredential creds) in D:\Source\htmlagilitypack.new\Trunk\HtmlAgilityPack\Ht mlWeb.cs:line 1479 at HtmlAgilityPack.HtmlWeb.Load(String url, String method) in D:\Source\htmla gilitypack.new\Trunk\HtmlAgilityPack\HtmlWeb.cs:line 1103 at HtmlAgilityPack.HtmlWeb.Load(String url) in D:\Source\htmlagilitypack.new\ Trunk\HtmlAgilityPack\HtmlWeb.cs:line 1061 at SimpleChartParser.AppAnnieParser.ParseOneDetail(ApplicationInfo appInfo) i n c:\users\nhn60\documents\visual studio 2010\Projects\FunToolPack\SimpleChartPa rser\AppAnnieParser.cs:line 90 at SimpleChartParser.AppAnnieParser.<ParseDetails>b__0(ApplicationInfo ai) in c:\users\nhn60\documents\visual studio 2010\Projects\FunToolPack\SimpleChartPar ser\AppAnnieParser.cs:line 80 at System.Threading.Tasks.Parallel.<>c__DisplayClass21`2.<ForEachWorker>b__17 (Int32 i) at System.Threading.Tasks.Parallel.<>c__DisplayClassf`1.<ForWorker>b__c() at System.Threading.Tasks.Task.InnerInvoke() at System.Threading.Tasks.Task.InnerInvokeWithArg(Task childTask) at System.Threading.Tasks.Task.<>c__DisplayClass7.<ExecuteSelfReplicating>b__ 6(Object ) --- End of inner exception stack trace --- at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceled Exceptions) at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationTo ken cancellationToken) at System.Threading.Tasks.Parallel.ForWorker[TLocal](Int32 fromInclusive, Int 32 toExclusive, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWit hState, Func`4 bodyWithLocal, Func`1 localInit, Action`1 localFinally) at System.Threading.Tasks.Parallel.ForEachWorker[TSource,TLocal](TSource[] ar ray, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Act ion`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEveryt hing, Func`1 localInit, Action`1 localFinally) at System.Threading.Tasks.Parallel.ForEachWorker[TSource,TLocal](IEnumerable` 1 source, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState , Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithE verything, Func`1 localInit, Action`1 localFinally) at System.Threading.Tasks.Parallel.ForEach[TSource](IEnumerable`1 source, Act ion`1 body) at SimpleChartParser.AppAnnieParser.ParseDetails() in c:\users\nhn60\document s\visual studio 2010\Projects\FunToolPack\SimpleChartParser\AppAnnieParser.cs:li ne 80 at SimpleChartParser.Program.Main(String[] args) in c:\users\nhn60\documents\ visual studio 2010\Projects\FunToolPack\SimpleChartParser\Program.cs:line 15

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >