thread-safety

“BindingSource cannot be its own data source” - error when trying to reset the binding source from a method in another class

六眼飞鱼酱① 提交于 2020-01-11 05:06:30
问题 We are binding a DataGridview using BindingSource . So in the main thread we have given like this. class1BindingSource = new BindingSource(); class1BindingSource.DataSource = class1List; this.dataGridView1.DataSource = class1BindingSource; After that i have a placed a background worker in the form and is triggering in a button click. i.e. in the button click this.backgroundWorker1.RunWorkerAsync() In the BackgroundWorker DoWork Event i am trying to update the BindingSource and there by trying

How to use an AppDomain to limit a static class' scope for thread-safe use?

家住魔仙堡 提交于 2020-01-11 02:11:10
问题 I have been bitten by a poorly architected solution. It is not thread safe! I have several shared classes and members in the solution, and during development all was cool... BizTalk has sunk my battle ship. We are using a custom BizTalk Adapter to call my assemblies. The Adapter is calling my code and running things in parallel, so I assume it is using multiple threads all under the same AppDomain. What I would like to do is make my code run under its own AppDomain so the shared problems I

Is unique_ptr thread safe?

老子叫甜甜 提交于 2020-01-10 17:26:23
问题 Is unique_ptr thread safe? Is it impossible for the code below to print same number twice? #include <memory> #include <string> #include <thread> #include <cstdio> using namespace std; int main() { unique_ptr<int> work; thread t1([&] { while (true) { const unique_ptr<int> localWork = move(work); if (localWork) printf("thread1: %d\n", *localWork); this_thread::yield(); } }); thread t2([&] { while (true) { const unique_ptr<int> localWork = move(work); if (localWork) printf("thread2: %d\n",

Primitive synchronization primitives — safe?

◇◆丶佛笑我妖孽 提交于 2020-01-10 05:07:06
问题 On constrained devices, I often find myself "faking" locks between 2 threads with 2 bools. Each is only read by one thread, and only written by the other. Here's what I mean: bool quitted = false, paused = false; bool should_quit = false, should_pause = false; void downloader_thread() { quitted = false; while(!should_quit) { fill_buffer(bfr); if(should_pause) { is_paused = true; while(should_pause) sleep(50); is_paused = false; } } quitted = true; } void ui_thread() { // new Thread(downloader

Volatile Violates its main job?

倖福魔咒の 提交于 2020-01-09 18:59:25
问题 According to MSDN: The volatile keyword indicates that a field might be modified by multiple threads that are executing at the same time. Fields that are declared volatile are not subject to compiler optimizations that assume access by a single thread. This ensures that the most up-to-date value is present in the field at all times. Please notice the last sentence: This ensures that the most up-to-date value is present in the field at all times. However, there's a problem with this keyword. I

Fortran OpenMP with subroutines and functions

徘徊边缘 提交于 2020-01-09 10:52:01
问题 Disclaimer: I'm quite certain that this has been answered somewhere, but myself and another person have been searching quite hard to no avail. I've got a code that looks something like this: PROGRAM main !$omp parallel do !$omp private(somestuff) shared(otherstuff) DO i=1,n ... CALL mysubroutine(args) ... a=myfunction(moreargs) ... ENDDO !$omp end parallel do END PROGRAM SUBROUTINE mysubroutine(things) ... END SUBROUTINE FUNCTION myfunction(morethings) ... END FUNCTION I cannot determine

Fortran OpenMP with subroutines and functions

[亡魂溺海] 提交于 2020-01-09 10:50:54
问题 Disclaimer: I'm quite certain that this has been answered somewhere, but myself and another person have been searching quite hard to no avail. I've got a code that looks something like this: PROGRAM main !$omp parallel do !$omp private(somestuff) shared(otherstuff) DO i=1,n ... CALL mysubroutine(args) ... a=myfunction(moreargs) ... ENDDO !$omp end parallel do END PROGRAM SUBROUTINE mysubroutine(things) ... END SUBROUTINE FUNCTION myfunction(morethings) ... END FUNCTION I cannot determine

What does threadsafe mean?

99封情书 提交于 2020-01-08 13:25:09
问题 Recently I tried to Access a textbox from a thread (other than the UI thread) and an exception was thrown. It said something about the "code not being thread safe" and so I ended up writing a delegate (sample from MSDN helped) and calling it instead. But even so I didn't quite understand why all the extra code was necessary. Update: Will I run into any serious problems if I check Controls.CheckForIllegalCrossThread..blah =true 回答1: Eric Lippert has a nice blog post entitled What is this thing

Thread - concurrency issue

放肆的年华 提交于 2020-01-07 09:03:26
问题 Table with column "count". It has primary key "rowID". Now I want to fetch this count, increment it by 1 and update it. I have a scenario where multiple instances / threads try to update the same column - count. For eg. 3 threads t1,t2,t3 (not synchronised). t1 fetches count(say 0) and increments and updates. Now count would be 1. Now there is a chance that t2 and t3 might try to access the count simultaneously and then issues arise. Please suggest right way to handle this scenario. 回答1: This

How can I interrupt a thread created from within a method?

醉酒当歌 提交于 2020-01-06 20:23:56
问题 I know that you can interrupt a thread created from say a runnable class, but how can I interrupt this thread I created from a method? Using a volatile boolean isn't working for me, so I assume either there is a better way to do this, or I need to somehow interrupt it. I don't want to interrupt all threads, just this one. I created a method that kicks off a Thread like this: public static void StartSyncThread() { new Thread() { public void run() { isRunning = true; // Set to true so while