multithreading

Portable Compare And Swap (atomic operations) C/C++ library?

Is there any small library, that wrapps various processors' CAS-like operations into macros or functions, that are portable across multiple compilers? PS. The atomic.hpp library is inside boost::interprocess::detail namespace. The author refuses to make it a public, well maintained library. Lets reopen the question, and see if there ar...

Is msgsnd() thread- and/or process-safe ?

What happens if two pthreads are calling the msgsnd() function at the "same" time, posting message to the same message queue ? What if two processes do the same ? Does it matter if they are threads or processes ? Specifically interested for Linux 2.6.15-2.5 #1 SMP PREEMPT Tue Sep 19 10:56:25 CDT 2006 x86_64 x86_64 x86_64 GNU/Linux ...

Java, "bind" something to a Thread

Hi, I was just wonderhing how some libraries can detect in which thread they run and "bind" something to it... for example the Mapped Diagnostic Context (MDC) of log4j or Context.enter() from Mozilla Rhino. How could i do that, just in case i'll stumble upon a case where i need this. ;-) Have a nice day! ...

Dynamic changes to thread stack size in Solaris 9 ?

Hello, I am looking for a configurable / tunable on Solaris 9 through which I can change the default thread stack size without recompiling the code to use "pthread_attr_setstacksize" For example on HPUX 11.11 / 11.23 the environment variable "PTHREAD_DEFAULT_STACK_SIZE" can be exported (available via HPUX patches PHCO_38307 / PHCO_3895...

Execute Background Task In Javascript

I have a cpu intensive task that I need to run on the client. Ideally, I'd like to be able to invoke the function and trigger progress events using jquery so I can update the UI. I know javascript does not support threading, but I've seen a few promising articles trying to mimic threading using setTimeout. What is the best approa...

Best practice to handle exception, that is thrown within catch block, in a thread. (.NET)

What's your opinion in handling exceptions within a thread's execution? More specifically, what if the exception is thrown inside catch block of an try-catch clause? And what happen to the thread if the exception is unhandled? ...

Threads, TableViewController, View Transition Question. iPhone

In my app when a user clicks a button I want to show a loading screen, then call a method that will load the data from the network and then load a view that displays the data in a UITableView. I have everything working except showing the loading screen. (UI hangs due to the fact that the network data/parsing logic is executing) Can anyon...

What object should I lock on when I am passing a Collection<Foo> into a separate class ?

Please refer to UML The Connection class's constructor initializes its foos member via foos = Collections.synchronizedList( new ArrayList<Foo>(10) ); When Connection#start() is invoked, it creates an instance of Poller (while passing the foos reference into Poller's constructor) & Poller is started (Poller is a Runnable). Question: ...

Calling a method when thread terminates

I have a form that starts a thread. Now I want the form to auto-close when this thread terminates. The only solution I found so far is adding a timer to the form and check if thread is alive on every tick. But I want to know if there is a better way to do that? Currently my code looks more less like this partial class SyncForm : Form ...

Monitor vs Mutex in c#

What is the difference between a Monitor and a Mutex in C#? When to use a Monitor and when to use a Mutex in C#? ...

Patterns/Principles for thread-safe queues and "master/worker" program in Java

I have a problem which I believe is the classic master/worker pattern, and I'm seeking advice on implementation. Here's what I currently am thinking about the problem: There's a global "queue" of some sort, and it is a central place where "the work to be done" is kept. Presumably this queue will be managed by a kind of "master" object. ...

Degrading gracefully with Web Workers

So I'm starting to hear more and more about Web Workers. I think it's absolutely fantastic, but the question I haven't seen anyone really tackle so far is how to support older browsers that do not yet have support for the new technology. The only solution I've been able to come up with so far is to make some sort of wrapper around the ...

Force Program / Thread to use 100% of processor(s) resources

I do some c++ programming related to mapping software and mathematical modeling. Some programs take anywhere from one to five hours to perform and output a result; however, they only consume 50% of my core duo. I tried the code on another dual processor based machine with the same result. Is there a way to force a program to use all ava...

I have a server listening on sockets, whats a good approach to service CPU-bound requests with multiple threads?

I've got an application, written in C++, that uses boost::asio. It listens for requests on a socket, and for each request does some CPU-bound work (e.g. no disk or network i/o), and then responds with a response. This application will run on a multi-core system, so I plan to have (at least) 1 thread per core, to process requests in par...

If I lock when writing to a variable, do I also need to lock when reading, if the read is otherwise atomic?

I have a class with code as follows private readonly object m_lock = new object(); private IClient m_client private object m_context; When setting the client and context, I lock as follows lock(m_lock) { m_client = theClientFromSomewhere; m_context = contextObject; } My question is, if I only need to get the m_client by it...

How do I setup log4j properties so that each thread outputs to its own log file?

Hello all, I have multiple instances of a thread class running at any given time. I have log4j setup to be used for logging needs. I need a way to setup log4j so that every instance of my thread class outputs its log in a different log file. Here is what I have done ( in pseudo code) public class doSomething extends Thread { pri...

c# threading and databases

hello, I've got a winform with some child forms on it. Now I'm accessing the child forms by a treeview in my main form. Now in that treeview is a list of websites. Since a website is actually a group of pages, this is also shown in the tree. Website is my parent and the pages are the childs. When you click on one of the pages the stati...

WCf server busy threads single-core

I am trying to set up a service and I keep getting the following error The HTTP service located at http://localhost/Service1.svc is too busy. Its very annoying problem that I wish I could fix. I am not overloading the system but I am using Threads in my program. Maybe I should disable them? no? I am using an old computer running Ser...

Segmentation fault during Transition of Control from C++ to Pro *C

Hi, I have written a small Pro *C/C++ application [ multi-threaded, daemon ] where, i used Pro *c to fetch some DB records and then call C++ function to generate XML files, which are sent through socket to third party. The problem is that, when the c++ function is called, it is generating the xml file properly, but ending up with Sig 1...

Increase thread priority on wait handles

Hi everyone ! I am running a application with a LOT of thread. All these threads are updating database with GPS coordinates. Meanwhile, the application can receive a synchronization request. Before the server can process this request, all the writing threads have to finish their job. Therefore I am using an array of wait handles to mana...