multithreading

Directory walker on modern operating systems slower when it's multi-threaded?

北城以北 提交于 2020-02-01 09:29:28
问题 Once I had the theory that on modern operating systems multithreaded read access on the HDD should perform better. I thought that: the operating system queues all read requests, and rearranges them in such a way, that it could read from the HDD more sequentially. The more requests it would get, the better it could rearrange them to optimize the read sequence. I was very sure that I read it somewhere few times. But I did some benchmarking, and had to find out, that multithreaded read access

Directory walker on modern operating systems slower when it's multi-threaded?

断了今生、忘了曾经 提交于 2020-02-01 09:28:45
问题 Once I had the theory that on modern operating systems multithreaded read access on the HDD should perform better. I thought that: the operating system queues all read requests, and rearranges them in such a way, that it could read from the HDD more sequentially. The more requests it would get, the better it could rearrange them to optimize the read sequence. I was very sure that I read it somewhere few times. But I did some benchmarking, and had to find out, that multithreaded read access

Python: update argument in thread

淺唱寂寞╮ 提交于 2020-02-01 08:36:50
问题 I was wondering if it would be possible to start a new thread and update its argument when this argument gets a new value in the main of the program, so something like this: i = 0 def foo(i): print i time.sleep(5) thread.start_new_thread(foo,(i,)) while True: i = i+1 Thanks a lot for any help! 回答1: An argument is just a value, like anything else. Passing the value just makes a new reference to the same value, and if you mutate that value, every reference will see it. The fact that both the

Python: update argument in thread

喜欢而已 提交于 2020-02-01 08:35:46
问题 I was wondering if it would be possible to start a new thread and update its argument when this argument gets a new value in the main of the program, so something like this: i = 0 def foo(i): print i time.sleep(5) thread.start_new_thread(foo,(i,)) while True: i = i+1 Thanks a lot for any help! 回答1: An argument is just a value, like anything else. Passing the value just makes a new reference to the same value, and if you mutate that value, every reference will see it. The fact that both the

Why is the logical call context not propagated across threads?

允我心安 提交于 2020-02-01 07:07:04
问题 I have a weird problem with logical call contexts not propagating to threads in my application. In this sample, the thread (created before logical call context data is set) does not pick up the new value: class Program { static void Main(string[] args) { var dispatcher = new MessageDispatcher(); //Logical call context data not set yet Console.WriteLine($"Main: {Thread.CurrentThread.ManagedThreadId}: {CallContext.LogicalGetData("myvar")}"); // Main logical call context data is not set yet =

C# - Locking a resource when obtained from dictionary

拜拜、爱过 提交于 2020-02-01 06:27:31
问题 I have a Dictionary that tracks objects (ClientObject). Both the dictionary and ClientObject's are accessed by multiple threads. When I modify or read any object in this dictionary, I obtain a read or write lock on the dictionary using ReaderWriterLockSlim (rwl_clients) then obtain an exclusive lock on the actual object. I just wanted to know if I am using these .net threading facilities correctly Example: rwl_clients.EnterReadLock(); ClientObject clobj; if(!m_clients.TryGetValue(key, out

C# - Locking a resource when obtained from dictionary

泄露秘密 提交于 2020-02-01 06:26:30
问题 I have a Dictionary that tracks objects (ClientObject). Both the dictionary and ClientObject's are accessed by multiple threads. When I modify or read any object in this dictionary, I obtain a read or write lock on the dictionary using ReaderWriterLockSlim (rwl_clients) then obtain an exclusive lock on the actual object. I just wanted to know if I am using these .net threading facilities correctly Example: rwl_clients.EnterReadLock(); ClientObject clobj; if(!m_clients.TryGetValue(key, out

Background thread vs UI thread

拥有回忆 提交于 2020-02-01 03:24:24
问题 Could any one help me to figure out background thread and UI thread in C#.I have googled it but i coudnt find article illustrate both. 回答1: A UI thread creates UI elements and waits and responds to events like mouse clicks and key presses. You can only access the UI elements from the UI thread. There are two types of threads: background and foreground. A UI thread is an example of a foreground thread. The difference between background and foreground threads is pretty simple. Background

OpenCV & Python Multithreading - Seeking within a VideoCapture Object

天涯浪子 提交于 2020-01-31 10:29:07
问题 I've been working on a python application which uses OpenCV to read frames from a video and create a composite of the "activity", i.e. the things that have changed from one frame to the next. To do that, I only really want to check one frame per second or so. For a long time I've been using the following code (simplified, with some error checking, classes, etc removed for brevity) to get the video object and the first frame: video_capture = cv2.VideoCapture(video_fullpath) this_frame = get

Polling the right way?

僤鯓⒐⒋嵵緔 提交于 2020-01-30 14:16:10
问题 I am a software/hardware engineer with quite some experience in C and embedded technologies. Currently i am busy with writing some applications in C# (.NET) that is using hardware for data acquisition. Now the following, for me burning, question: For example: I have a machine that has an endswitch for detecting the final position of an axis. Now i am using a USB Data acquisition module to read the data. Currently I am using a Thread to continuously read the port-status. There is no interrupt