Search Results

Search found 5945 results on 238 pages for 'green threads'.

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

  • MySQL Locks: order of unblocked threads

    - by teehoo
    I have a MySQL ISAM table being accessed my multiple php instances. Right now I'm using a WRITE lock to serialize access to this table. My question is how do I ensure that the PHP instances get served on a First-Come-First-Serve basis? Or is this the default behaviour? The official MySQL documentation doesn't mention anything about the blocked thread order for threads of the same lock type (ie multiple threads attempting a WRITE LOCK). It only mentions that a WRITER will jump to the front of the waiting queue if READERS are waiting.

    Read the article

  • Access static constant variable from multiple threads in C

    - by user325519
    I have some experience with multithread programming under Linux (C/C++ & POSIX threads), however most obvious cases are sometimes very complicated. I have several static constant variables (global and function local) in my code, can I access them simultaneously from multiple threads without using mutexes? Because I don't modify them it should be ok, but it's always better to ask. I have to do heavy speed optimization, so even as fast operations as mutex lock/unlock are quite expensive for me, especially because my application is going to access these variables form long loops.

    Read the article

  • Boost Shared Pointer: Simultaneous Read Access Across Multiple Threads

    - by Nikhil
    I have a thread A which allocates memory and assigns it to a shared pointer. Then this thread spawns 3 other threads X, Y and Z and passes a copy of the shared pointer to each. When X, Y and Z go out of scope, the memory is freed. But is there a possibility that 2 threads X, Y go out of scope at the exact same point in time and there is a race condition on reference count so instead of decrementing it by 2, it only gets decremented once. So, now the reference count newer drops to 0, so there is a memory leak. Note that, X, Y and Z are only reading the memory. Not writing or resetting the shared pointer. To cut a long story short, can there be a race condition on the reference count and can that lead to memory leaks?

    Read the article

  • mysql database design: threads and replies

    - by ajsie
    in my forum i have threads and replies. one thread has multiple replies. but then, a reply can be a reply of an reply (like google wave). because of that a reply has to have a column "reply_id" so it can point to the parent reply. but then, the "top-level" replies (the replies directly under the thread) will have no parent reply. so how can i fix this? how should the columns be in the reply table (and thread table). at the moment it looks like this: threads: id title body replies: id thread_id (all replies will belong to a thread) reply_id (here lies the problem. the top-level replies wont have a parent reply) body what could a smart design look like to enable reply a reply?

    Read the article

  • Threads in JAVA

    - by theband
    I was today asked in an interview over the Thread concepts in JAVA? The Questions were... What is a thread? Why do we go for threading? A real time example over the threads. Can we create threads in Spring framework service class. Can flex call a thread? I did not answer any questions apart from definition of Thread, that too i just learnt from internet. Can anyone explain me clearly over this.

    Read the article

  • Help regarding C# thread pool

    - by Matt
    I have a method that gets called quite often, with text coming in as a parameter.. I'm looking at creating a thread pool that checks the line of text, and performs actions based on that.. Can someone help me out with the basics behind creating the thread pool and firing off new threads please? This is so damn confusing..

    Read the article

  • Synchronizing thread communication?

    - by Roger Alsing
    Just for the heck of it I'm trying to emulate how JRuby generators work using threads in C#. Also, I'm fully aware that C# haas built in support for yield return, I'm just toying around a bit. I guess it's some sort of poor mans coroutines by keeping multiple callstacks alive using threads. (even though none of the callstacks should execute at the same time) The idea is like this: The consumer thread requests a value The worker thread provides a value and yields back to the consumer thread Repeat untill worker thread is done So, what would be the correct way of doing the following? //example class Program { static void Main(string[] args) { ThreadedEnumerator<string> enumerator = new ThreadedEnumerator<string>(); enumerator.Init(() => { for (int i = 1; i < 100; i++) { enumerator.Yield(i.ToString()); } }); foreach (var item in enumerator) { Console.WriteLine(item); }; Console.ReadLine(); } } //naive threaded enumerator public class ThreadedEnumerator<T> : IEnumerator<T>, IEnumerable<T> { private Thread enumeratorThread; private T current; private bool hasMore = true; private bool isStarted = false; AutoResetEvent enumeratorEvent = new AutoResetEvent(false); AutoResetEvent consumerEvent = new AutoResetEvent(false); public void Yield(T item) { //wait for consumer to request a value consumerEvent.WaitOne(); //assign the value current = item; //signal that we have yielded the requested enumeratorEvent.Set(); } public void Init(Action userAction) { Action WrappedAction = () => { userAction(); consumerEvent.WaitOne(); enumeratorEvent.Set(); hasMore = false; }; ThreadStart ts = new ThreadStart(WrappedAction); enumeratorThread = new Thread(ts); enumeratorThread.IsBackground = true; isStarted = false; } public T Current { get { return current; } } public void Dispose() { enumeratorThread.Abort(); } object System.Collections.IEnumerator.Current { get { return Current; } } public bool MoveNext() { if (!isStarted) { isStarted = true; enumeratorThread.Start(); } //signal that we are ready to receive a value consumerEvent.Set(); //wait for the enumerator to yield enumeratorEvent.WaitOne(); return hasMore; } public void Reset() { throw new NotImplementedException(); } public IEnumerator<T> GetEnumerator() { return this; } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return this; } } Ideas?

    Read the article

  • Semaphores in unmanaged code

    - by Dororo
    I've been using the Semaphore class to create semaphores. However, the examples use managed code (requires /clr), and I need to use unmanaged code because it seems FreeType doesn't like working with managed code. How can I create two simple threads which use a semaphore in unmanaged code?

    Read the article

  • java background task

    - by markovuksanovic
    I was wondering which would be the most efficient approach to implement some kind of background task in java (I guess that would be some kind of nonblocking Threads). To be more precise - I have some java code and then at some point I need to execute a long running operation. What I would like to do is to execute that operation in the background so that the rest of the program can continue executing and when that task is completed just update some specific object which. This change would be then detected by other components.

    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

  • Implementing events to communicate between two processes - C

    - by Jamie Keeling
    Hello all! I have an application consisting of two windows, one communicates to the other and sends it a struct constaining two integers (In this case two rolls of a dice). I will be using events for the following circumstances: Process a sends data to process b, process b displays data Process a closes, in turn closing process b Process b closes a, in turn closing process a I have noticed that if the second process is constantly waiting for the first process to send data then the program will be just sat waiting, which is where the idea of implementing threads on each process occurred and I have started to implement this already. The problem i'm having is that I don't exactly have a lot of experience with threads and events so I'm not sure of the best way to actually implement what I want to do. Following is a small snippet of what I have so far in the producer application; Create thread: case IDM_FILE_ROLLDICE: { hDiceRoll = CreateThread( NULL, // lpThreadAttributes (default) 0, // dwStackSize (default) ThreadFunc(hMainWindow), // lpStartAddress NULL, // lpParameter 0, // dwCreationFlags &hDiceID // lpThreadId (returned by function) ); } break; The data being sent to the other process: DWORD WINAPI ThreadFunc(LPVOID passedHandle) { HANDLE hMainHandle = *((HANDLE*)passedHandle); WCHAR buffer[256]; LPCTSTR pBuf; LPVOID lpMsgBuf; LPVOID lpDisplayBuf; struct diceData storage; HANDLE hMapFile; DWORD dw; //Roll dice and store results in variable storage = RollDice(); hMapFile = CreateFileMapping( (HANDLE)0xFFFFFFFF, // use paging file NULL, // default security PAGE_READWRITE, // read/write access 0, // maximum object size (high-order DWORD) BUF_SIZE, // maximum object size (low-order DWORD) szName); // name of mapping object if (hMapFile == NULL) { dw = GetLastError(); MessageBox(hMainHandle,L"Could not create file mapping object",L"Error",MB_OK); return 1; } pBuf = (LPTSTR) MapViewOfFile(hMapFile, // handle to map object FILE_MAP_ALL_ACCESS, // read/write permission 0, 0, BUF_SIZE); if (pBuf == NULL) { MessageBox(hMainHandle,L"Could not map view of file",L"Error",MB_OK); CloseHandle(hMapFile); return 1; } CopyMemory((PVOID)pBuf, &storage, (_tcslen(szMsg) * sizeof(TCHAR))); //_getch(); MessageBox(hMainHandle,L"Completed!",L"Success",MB_OK); UnmapViewOfFile(pBuf); return 0; } I'm trying to find out how I would integrate an event with the threaded code to signify to the other process that something has happened, I've seen an MSDN article on using events but it's just confused me if anything, I'm coming up on empty whilst searching on the internet too. Thanks for any help Edit: I can only use the Create/Set/Open methods for events, sorry for not mentioning it earlier.

    Read the article

  • C#. How to terminate a thread which has spawned another thread which is sleeping?

    - by Bobb
    I have a long running thread made from Thread.Start(). It spawns a background thread using QueueUserWorkItem which sleeps most of the time. Then the class-owner get disposed I call thread1.Join() but naturally it doesnt return because its child background thread is sleeping. What would be the right solution to gracefully terminate a thread which has other threads with little hassle? Thanks

    Read the article

  • Multithreading, when to yield versus sleep

    - by aaa
    hello. To clarify terminology, yield is when thread gives up its time slice. My platform of interest is POSIX threads, but I think question is general. Suppose I have consumer/producer pattern. If I want to throttle either consumer or producer, which is better to use, sleep or yield? I am mostly interested in efficiency of using either function. Thanks

    Read the article

  • How to terminate a thread which has spawned another thread which is sleeping?

    - by Bobb
    I have a long running thread made from Thread.Start(). It spawns a background thread using QueueUserWorkItem which sleeps most of the time. Then the class-owner get disposed I call thread1.Join() but naturally it doesnt return because its child background thread is sleeping. What would be the right solution to gracefully terminate a thread which has other threads with little hassle?

    Read the article

  • how to know when a work in a thread is complete?

    - by seinkraft
    I need to create multiple threads when a button is clicked and i've done that with this: Dim myThread As New Threading.Thread(AddressOf getFile) myThread.IsBackground = True myThread.Start() but i need to update a picture box with the downloaded file, buy if i set an event in the function getFile and raise it to notify that the files was downloaded and then update the picturebox.

    Read the article

  • Creating semaphores with unmanaged code in C++

    - by Dororo
    I've been using the MSDN Library to create semaphores, located at: http://msdn.microsoft.com/en-us/library/system.threading.semaphore.aspx However, the examples are using Managed code (requires /clr), and I need to use Unmanaged code because FreeType doesn't like working with Managed code it seems. How would I go about creating 2 simple threads which use a semaphore if I'm using unmanaged code? Many thanks for your help.

    Read the article

  • Multithreaded ActiveRecord requests in rspec

    - by jeem
    I'm trying to recreate a race condition in a test, so I can try out some solutions. I find that in the threads I create in my test, ActiveRecord always returns 0 for counts and nil for finds. For example, with 3 rows in the table "foos": it "whatever" do puts Foo.count 5.times do Thread.new do puts Foo.count end end end will print 3 0 0 0 0 0 test.log shows the expected query, the expected 6 times: SELECT count(*) AS count_all FROM `active_agents` Any idea what's going on here?

    Read the article

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