synchronization

Threadpool program runs much slower on much faster server

帅比萌擦擦* 提交于 2019-11-30 07:37:20
upd I now think that root of my problem not "threading", because I observe slowdown at any point of my program. I think somehow when using 2 processors my program executes slower probably because two processors need to "communicate" between each other. I need to do some tests. I will try to disable one of the processors and see what happens. ==================================== I'm not sure if this is C# question, probably it more about hardware, but I think C# will be most suitable. I was using cheap DL120 server and I decided to upgrade to much more expensive 2 processors DL360p server.

SVN to Clearcase Export

大憨熊 提交于 2019-11-30 07:33:41
I have a client who is rather insistent about using Clearcase. Are there any tools/scripts that would allow my team to work against an SVN repository (or really anything other than Clearcase), but periodically automatically sync back changesets to the Clearcase VOB? My thinking is that if such a tool exists, and it's automatic, reliable, and transparent the client might be pursuaded to allow us to work against SVN. Thanks, Kent VonC I use Git directly within a ClearCase view. Then I could git2svn back the content to SVN if I had a SVN repo to synchronize with. Note: for a tool to work directly

How to address thread-safety of service data used for maintaining static local variables in C++?

时光毁灭记忆、已成空白 提交于 2019-11-30 07:33:16
Consider the following scenario. We have a C++ function with a static local variable: void function() { static int variable = obtain(); //blahblablah } the function needs to be called from multiple threads concurrently, so we add a critical section to avoid concurrent access to the static local: void functionThreadSafe() { CriticalSectionLockClass lock( criticalSection ); static int variable = obtain(); //blahblablah } but will this be enough? I mean there's some magic that makes the variable being initialized no more than once. So there's some service data maintained by the runtime that

How do I take ownership of an abandoned boost::interprocess::interprocess_mutex?

做~自己de王妃 提交于 2019-11-30 07:33:07
问题 My scenario: one server and some clients (though not many). The server can only respond to one client at a time, so they must be queued up. I'm using a mutex ( boost::interprocess::interprocess_mutex ) to do this, wrapped in a boost::interprocess::scoped_lock . The thing is, if one client dies unexpectedly (i.e. no destructor runs) while holding the mutex, the other clients are in trouble, because they are waiting on that mutex. I've considered using timed wait, so if I client waits for, say,

Wait until all Task finish in unit test

不打扰是莪最后的温柔 提交于 2019-11-30 07:01:12
I have this class I want to unit test: public class SomeClass { public void Foo() { Bar(); } private void Bar() { Task.Factory.StartNew(() => { // Do something that takes some time (e.g. an HTTP request) }); } } And this is how my unit test looks like: [TestMethod] public void TestFoo() { // Arrange var obj = new SomeClass(); // Act obj.Foo(); obj.Foo(); obj.Foo(); // Assert /* I need something to wait on all tasks to finish */ Assert.IsTrue(...); } So, I need to make the unit test thread wait until all tasks started in the Bar method have finished their job before starting my assertions.

how to create Synchronized arraylist

霸气de小男生 提交于 2019-11-30 06:58:46
问题 i have created synchronized arrayList like this import java.text.SimpleDateFormat; import java.util.*; class HelloThread { int i=1; List arrayList; public void go() { arrayList=Collections.synchronizedList(new ArrayList()); Thread thread1=new Thread(new Runnable() { public void run() { while(i<=10) { arrayList.add(i); i++; } } }); thread1.start(); Thread thred2=new Thread(new Runnable() { public void run() { while(true) { Iterator it=arrayList.iterator(); while(it.hasNext()) { System.out

How to sync two MySQL tables?

萝らか妹 提交于 2019-11-30 06:58:26
If I have a table (lets call it orders ) on one server of mine, named, for example, local . And I have this same table one another server of mine, named, for example, remote . My problem is, what is the best way to sync these two tables? I would like a solution that replaces a registry if the local is different of the remote one. And insert the registry if it doesn't exist on the local table. I had tried using dump a dump command similar to this one, but didn't worked as expected: /usr/bin/mysqldump --defaults-file=~/my/conf.cnf --skip-opt --skip-add-locks --default-character-set=latin1 -

Why does __sync_add_and_fetch work for a 64 bit variable on a 32 bit system?

落花浮王杯 提交于 2019-11-30 06:46:23
Consider the following condensed code: /* Compile: gcc -pthread -m32 -ansi x.c */ #include <stdio.h> #include <inttypes.h> #include <pthread.h> static volatile uint64_t v = 0; void *func (void *x) { __sync_add_and_fetch (&v, 1); return x; } int main (void) { pthread_t t; pthread_create (&t, NULL, func, NULL); pthread_join (t, NULL); printf ("v = %"PRIu64"\n", v); return 0; } I have a uint64_t variable that I want to increment atomically, because the variable is a counter in a multi-threaded program. To achieve the atomicity I use GCC's atomic builtins . If I compile for an amd64 system (-m64)

Synchronising twice on the same object?

那年仲夏 提交于 2019-11-30 06:20:25
问题 I was wondering if in Java I would get any odd behaviour if I synchronise twice on the same object? The scenario is as follows pulbic class SillyClassName { object moo; ... public void method1(){ synchronized(moo) { .... method2(); .... } } public void method2(){ synchronized(moo) { doStuff(); } } } Both methods use the object and are synchronised on it. Will the second method when called by the first method stop because it's locked? I don't think so because it's the same thread but I'm

C#'s lock() in Managed C++

半世苍凉 提交于 2019-11-30 06:11:15
Does managed C++ have an equivalent to C#'s lock() and VB's SyncLock? If so, how do I use it? The equivelent to a lock / SyncLock would be to use the Monitor class. In .NET 1-3.5sp, lock(obj) does: Monitor.Enter(obj); try { // Do work } finally { Monitor.Exit(obj); } As of .NET 4, it will be: bool taken = false; try { Monitor.Enter(obj, ref taken); // Do work } finally { if (taken) { Monitor.Exit(obj); } } You could translate this to C++ by doing: System::Object^ obj = gcnew System::Object(); Monitor::Enter(obj); try { // Do work } finally { Monitor::Exit(obj); } C++/CLI does have a 'lock'