Tag Info

New answers tagged

1

To ensure safety both threads must go and acquire the lock before messing with the data of student. If one thread doesn't do that then it's like neither thread acquired the lock. Part of acquiring the lock is waiting until no other thread has the lock.


3

What happens when a thread acquires a lock? No other thread can acquire that lock until it's released. Note that this is all that happens. Only methods called via other threads are affected. Only other threads that compete for the same lock are affected at all. This means that the holding thread can do whatever it likes, just as before the lock. ...


0

You can create an integration tier over your library's model using (for example) the apache camel integration framework. The Netty component probably could fit your needs. With an observable pattern your integration tier should transform your model's received changes and notify them to the front-end subscribers. Another similar way to interpret your ...


9

I read a really good blog some time ago which discuss this issue (mentioned by Karl Bielefeldt), what it basically says is that it is very dangerous to try and make the UI kit thread safe, as it introduces possible deadlocks and depending on how it's implemented, race conditions into the framework. There is also a performance consideration. Not so much ...


19

Toward the end of his failed dream essay, Graham Hamilton (a major Java architect) mentions if developers "are to preserve the equivalence with an event queue model, they will need to follow various non-obvious rules," and having a visible and explicit event queue model "seems to help people to more reliably follow the model and thus construct GUI programs ...


15

Threadedness (in a shared memory model) is a property that tends to defy abstraction efforts. A simple example is a Set-type: while Contains(..) and Add(...) and Update(...) is a perfectly valid API in a single threaded scenario, the multi-threaded scenario needs a AddOrUpdate. The same thing applies to the UI - if you want to display a list of items with a ...


22

Because making the GUI lib thread safe is a massive headache and a bottleneck. Control flow in GUIs often goes in 2 directions from the event queue to root window to the gui widgets and from the application code to the widget propagated up to the root window. Devising a locking strategy that isn't lock the root window (will cause a lot of contention) is ...


2

There are different ways to do it, but if you are inclined to stick with POCO, you may want to look at the macchina.io (OSP portion) WebEvent implementation - it is essentially a pub/sub messaging framework. There's more there than what you need but it's relatively simple and architecturally you should be able to quickly tailor it to your needs. I have used ...


0

In C++ for example, a const class or struct can have mutable members. Mutable members are typically used in situations where the logical value of an object doesn't change, but the internal representation my change. Changing mutable members is obviously not automatically thread safe. Therefore, accessing const objects is not automatically thread safe. ...


0

I would avoid doing this in PHP. You are going to hit a number of fundamental problems: the limit on concurrent requests on your clients browsers won't let them have 21 simultaneous requests open the connection limit in your web sever won't handle the incoming requests very well if you have more than a handful of concurrent users multithreading at the ...


0

If you are not familiar with threading, you could also use php to start a number of individual copies of the same program on the backend such as a linux box. Each of these would execute and could write their contents to uniquely names files in a directory. You could then collect the files as they were completed counting until you got all 21 files or you ...


1

One example of a system that used to work this way is the Linux kernel, which used to have a pair of functions called cli() and sti(). On single processor systems, these simply disabled and reenabled interrupts, thus preventing the current thread being stopped (on multiprocessor machines they were a little more complex). They were deprecated early in ...


3

You could rewrite your code this way in a pure async/await paradigm. private async void button1_Click(object sender, EventArgs e) { int r = await longRunningWork(); textBox1.Text += (r.ToString()); } private async Task<int> longRunningWork() { await Task.Delay(15000); return (new Random()).Next(10); ...


1

The whole point of condition variables is that you can suspend a thread until some (for that thread) external event occurs. The advantage of suspending a thread over letting it run continuously and check if it can continue is that a suspended thread does not needlessly consume CPU time and allows the processor to be used to perform useful tasks.


0

It depends. Without any synchronisation and without volatile or atomic variables it does not make a difference. However, if those methods change the object-state you will need some form of synchronisation, otherwise multiple threads would overwrite changes from other threads or just not see the change. Synchronisation is not free, volatile variables and ...


6

There's a lot of variety of schedulers because there's a lot of variety of needs, from real-time systems where the whole system is written in one go and the precise order and timing of scheduling is known when the device is built, to high-end systems where all threading is preemptive except for some very short sections deep inside the kernel. It certainly ...



Top 50 recent answers are included