>The code is totally and irrecoverably broken (from
a threading perspective).
>There is no way to fix it if it has to retain its current form.
Well... let's take the example of an interruptible
task. We have a main program which launches a thread.
Now, we want to stop this thread. We can use interruption
or the following code:
T1:
while(true)
{
lock lk(mutex);
if (end) break;
/* dosomething
*/
}
T2:
interruptT1()
{
lock lk(mutex);
end = true;
}
>The basic idea when using threads is to create parallelism. Thread
T1 is
>inherently non-parallel. It simply cannot operate in parallel with
anyone
>else who also needs to access the shared state that is protected by
the
>mutex.
That's what I call contention (when
your threads work in a collaborative way)...
*************************************************************************
This message and any attachments (the "message") are confidential and
intended solely for the addressees.
Any unauthorised use or dissemination is prohibited.
E-mails are susceptible to alteration.
Neither SOCIETE GENERALE nor any of its subsidiaries or affiliates
shall be liable for the message if altered, changed or falsified.
*************************************************************************