Tuesday, June 26, 2007

C++ threads in C++09

I noticed a recent post on Herb Sutter's blog about online talks on C++09, which included one talk in particular by Lawrence Crowl. If you're into SMP, multi-threading and synchronization, I suggest you look through that video. While the current C++ standard knows nothing of threads, let alone how to synchronize between them; C++09 will include atomic data types, mechanics to synchronize data updates across threads and a re-evaluated sequence point model. The details of the specification are still in the rough, but the posted video does provide some insight with regard to how, but more importantly why, the various additions are being made.

It appears my ThreadSynch library will be going out of business:) It's nice to see that I was onto something, though, especially with the exception re-throwing across threads.

6 kommentarer:

Wolfie said...

"especially with the exception re-throwing across threads"

Now why would you want to do that? Looks like you have your design wrong because you are looking to control flow using an exception interrupt.

Einar Otto Stangvik said...

No, I'm absolutely not using it to control flows. My reference is to the Threadsynch library, which enables you to capture exceptions in remote worker threads, and have them rethrown in the client thread.

Wolfie said...

That sounds cool on the face of it but I'm still not convinced its a good idea. An exception is a linear control interrupt and in a multi-threaded scenario that doesn't always make sense because execution is not necessarily linear.

The main thread should only be "managing" the main program environment if it uses threading. So say a console app would start-up, initialise objects then quietly await shutdown/completion/fatal error while the threads do all the work.

If a thread throws and exception I handle it there, log it and if its non-recoverable signal the main process thread to signal the other threads to terminate gracefully and exit.

Perhaps you could outline an example problem to illustrate?

Einar Otto Stangvik said...

Well it's really the only good alternative if you wish to execute tasks in worker threads. The other options would be to 1. suppress the exception; 2. catch the exception and store relevant information about it; 3. not handle the exception at all, and let the entire application terminate. Of the three, #2 really isn't an option at all, since there's no generic way of retrieving information about c++ exceptions.

Do note that this isn't threading in the usual sense of the concept, though. My ThreadSynch library enables a user to execute operations in other threads, e.g. have the owning thread of a specific class instance deal with all operations on that instance. You can read more about it in my (soon to be updated and refurbished) article at http://www.codeproject.com/threads/threadsynch.asp.

Anonymous said...

Making last chaos gold is the old question : Honestly there is no fast way to make lots of lastchaos gold. Sadly enough a lot of the people that all of a sudden come to with millions of lastchaos moneyalmost overnight probably duped . Although there are a lot of ways to make lots of buy last chaos goldhere I will tell you all of the ways that I know and what I do to make cheap lastchaos gold.

goonzu gold
is one of the hardest theme for every class at the beginning . You must have a good way to manage your goonzu money.If yor are a lucky guy ,you can earn so many buy goonzu gold by yourself . But if you are a not , I just find a nice way to get goonzu online gold. If you need , you can buy cheap goonzu gold at our website . Go to the related page and check the detailed information . Once you have any question , you can connect our customer service at any time .

Anonymous said...

aion chinaaion china gold,
aion cn goldaion chinese gold,
aion gold chinaaion gold chinese,
china aion goldchinese aion gold,
aion china kinaaion chinese kina,
aion kina chinachina aion kina,
aion china buybuy aion china,
aion chinese server goldaion cn server gold,
aion china server goldchina aion server gold,
chinese aion server goldaion chinese server gold,
aion cn server kinaaion china server kina,
china aion server kinachinese aion server kina