thread-safety

Is it safe to store an ObjectContext in a thread static variable in ASP.NET?

I've read that I should store an ObjectContext in HttpContext.Current in order to share my ObjectContext across different services/repositories that are called in a request. I'm wondering if it is safe to use an ObjectContext with the [ThreadStatic] attribute on a static class variable instead. Is that a safe thing to do? Is each request...

java detect no other threads are in an object

I am writing a class (Foo) which, when instantiated, can be called from multiple threads. Most methods of the Foo class can safely be called by multiple threads in parallel. One method of this class (logout()), requires that all other threads are done. Before logout is called, the reference to foo is deleted from a thread-safe collect...

Java object implements Runnable, how to remove the object from a collection

I have a java object that implements Runnable. here is the code. public class Obj implements Runnable { boolean shouldRun; private int stuff public Obj() { this.setshouldRun(true); stuff = 0; } public synchronized void setshouldRun(boolean shouldRun) { this.shouldRun = shouldRun; } public ...

Lazy sockets - scalability?

Asking more in theory, how could I build a server (or app) that uses lazy sockets? I'm envisioning a web app that moves all of its data via JSON exchanges to a central API-like servlet. I could leave the HTTP connection open for a bit after transferring all data, to write more to the client, as a sort of lazy push technology. The browser...

What happens when object running thread A is destroyed by thread B?

I may be greatly misunderstanding this threading scenario, but that's why I'm asking. What would/might happen in the following situation (assume C# threading)? Note: this scenario is simplified to the core issue, extra functionality is ignored. I have 2 objects, a and b, which are instances of classes A and B respectively; 'b' is a me...

Ruby 1.8.6, SQLite3 thread safety.

Is the sqlite3 Ruby gem thread safe? I can't find any documentation to say that it is. In my experiments, accessing a database from multiple Ruby threads eventually leads to the following error: /Library/Ruby/Gems/1.8/gems/sqlite3-ruby-1.2.5/lib/sqlite3/driver/native/driver.rb:84: [BUG] Bus Error Is there anything I'm missing? If not...

Are Database operations thread safe?

Hi, I am using sqlite in my iPhone app. I have some database operations, in which I have to insert into two tables different data(means there is no data-dependency). Can I perform these two operations in seperate thread. While the insert operation in each table are more than one. So I am doing this in a while loop also. ...

Which Swing component methods are thread safe?

According to Swing tutorial: Some Swing component methods are labelled "thread safe" in the API specification; these can be safely invoked from any thread. All other Swing component methods must be invoked from the event dispatch thread. Programs that ignore this rule may function correctly most of the time, but are subject to unpred...

How much thread-safety is too much?

I've been reading Java Concurrency in Practice lately – great book. If you think you know how concurrency works, but then most of the time you face the real issues, it feels like SWAG is the most you can do, then this book will certainly shed some light on the topic. It's sort of scary how many things can actually go wrong when you try t...

Using request.getSession() as a locking object?

I have some java code that gets and sets a session attribute: Object obj = session.getAttribute(TEST_ATTR); if (obj==null) { obj = new MyObject(); session.setAttribute(obj); } In order to make this code thread-safe, I'd like to wrap it in a synchronized block. But what do I use as the locking object? Does it make sense to use th...

Threadsafe Lazy Class

I have class Lazy which lazily evaluates an expression: public sealed class Lazy<T> { Func<T> getValue; T value; public Lazy(Func<T> f) { getValue = () => { lock (getValue) { value = f(); getValue = () => value; }...

BizTalk mapper and the [ThreadStatic] attribute

I've recently encountered an issue with the multi-threaded nature of the BizTalk Mapper and how it handles external assemblies. As this quote from MSDN indicates: Important Any code written in an external assembly for use in a scripting functoid needs to be thread safe. This is required because multiple instances of a map c...

Wicket: how to synchronize requests within session

Scenario: Apache Wicket based web application running on Tomcat server. User opens URL in browser, session is created and simple main page is shown in browser, user clicks on button and AJAX call is invoked. Application gets request and doing some stuff preparing response. In same time user or JavaScript in browser invokes another AJAX...

Basic Java threading issue

Lets say I'm interacting with a system that has two incrementing counters which depend on each other (these counters will never decrement): int totalFoos; // barredFoos plus nonBarredFoos int barredFoos; I also have two methods: int getTotalFoos(); // Basically a network call to localhost int getBarredFoos(); // Basically a network call...

Is LWP::UserAgent not thread-safe?

I'm running 40-or-so threads with the following subroutine: my $app = shift; my $ua = LWP::UserAgent->new(); $ua->timeout(5); my $response = $ua->get($$app{'watch_url'}); my $new_md5; if ($response->is_success()) { $new_md5 = md5_hex($response->content()); } return ($$app{'short_name'}, $$app{'watch_md5'}, $new_md5); Core dumps en...

Thread safety of std::map for read-only operations.

I have a std::map that I use to map values (field ID's) to a human readable string. This map is initialised once when my program starts before any other threads are started, and after that it is never modified again. Right now, I give every thread its own copy of this (rather large) map but this is obviously inefficient use of memory and...

Bring data came from async operation to main thread.

This is a "problem" i have with data that i receive from a library that has some Async operations on sending and receiving data. While i receive data and get data in my Mobile Windows Form or Desktop i need to deal with the cross thread operation. I deal with this while checking InvokeRequired and do Action if true...etc...But, what i re...

Are static methods in ASP.NET code-behind classes non-thread-safe?

Can I use static methods in my ASP.NET Pages and UserControls classes if they don't use any instance members? I.e.: protected void gridView_PageIndexChanging(object sender, GridViewPageEventArgs e) { gridStatement.DataSource = CreateDataSource(); gridStatement.PageIndex = e.NewPageIndex; gridStatement.DataBind(); } private ...

Why are locks performed on separate objects?

Possible Duplicate: Difference between lock(locker) and lock(variable_which_I_am_using) In all of the "thread-safe" code examples i've seen, they lock on a separate dummy object. Why cant locks be directly performed on the data in question? ...

Are the SetValue/GetValue methods of System.Array thread-safe?

We had a little discussion in the office, and got no documented answer: Is System.Array.SetValue thread safe? using System; using System.Text; using System.Threading; namespace MyApp { class Program { private static readonly object[] arr = new object[3]; static void Main(string[] args) { st...