Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - TA

Pages: [1]
1
General Discussion about just::thread / ATOMIC_VAR_INIT
« on: February 17, 2011, 03:22:57 PM »
Anthony,

Could you please explain what ATOMIC_VAR_INIT is used for? I couldn't find any useful information on that (or maybe I just coulnd't get it). As far as I understood it is used to initialize atomic variables in some special way, but what kind of initialization is done? When it might be useful? All the examples I could find was
atomic<int> t = ATOMIC_VAR_INIT(2);
why not just
atomic<int> t = 2;
what's the difference?

2
General Discussion about just::thread / unaligned atomic variables
« on: February 16, 2011, 08:55:15 AM »
Hi Anthony,

It might be useful to have assertion for unaligned atomic variables. For example:
Code: [Select]
#pragma pack(1)

struct X
{
std::atomic_char a;
std::atomic_long b;
};
As plain loads and stores are guaranteed to be atomic on x86 only in case of aligned read/write this structure may cause problems. In example above atomic_long is not properly aligned (I guess internal representation too), so I think it will be good idea to notify user (at least in debug mode) that library is not going to work as expected. Or alternatively you can explicitly align internal variable to the required boundary (I think this one is a better solution).
What do you think?

Here is the example that produces data race with atomic variables. In the loop I'm trying to place one variable into two different cache lines. I changed alignment explicitly, however it might be changed from compiler settings and not be so obvious (although even problems caused by explicit change might look unobvious for people that are not aware of memory alignment requirement for atomic operations).

Code: [Select]
#include <iostream>
#include <thread>
#include <atomic>

void thread1(std::atomic_long& x)
{
for (int i = 0; i < 1000000; ++i)
{
x.store(0);
long value = x.load();
assert(value == 0 || value == ~0);
}
}

void thread2(std::atomic_long& x)
{
for (int i = 0; i < 1000000; ++i)
{
x.store(~0);
long value = x.load();
assert(value == 0 || value == ~0);
}
}

#pragma pack(push)
#pragma pack(1)
struct X
{
char alignment;
std::atomic_long x;
};
#pragma pack(pop)

int main()
{
X arr[100];
for (int i = 0; i < 100; ++i)
{
std::cout << i << std::endl;
arr[i].x = 0;
std::thread thread(thread1, std::ref(arr[i].x));
thread2(arr[i].x);
thread.join();
}
}

Thanks.

3
Hi Anthony,

Thanks for the new release.
Just want to note that there is no std::copy_exception function in n3225 anymore, it is replaced with std::make_exception (18.8.5, page 470).

If I see anything else I'll post it here.

Thanks.

4
General Discussion about just::thread / Thread Local Storage
« on: February 03, 2011, 02:20:45 PM »
Hello Anthony,

Thread Local Storage is added as a keyword to C++ standard and it's not possible to have it in library without any special support by compiler, however it would be useful to have a portable TLS in just::thread. I couldn't find anything like that in documentation and forum, so could you please tell me if there is TLS support in just::thread?

Thanks.

5
General Discussion about just::thread / std::kill_dependency
« on: December 16, 2010, 05:34:13 PM »
Hi Anthony,

It was interesting to me how does std::kill_dependency implemented and I looked at the code of this function..It looks pretty much interesting. Does it really kill the dependency or it is provided just to support standard?

Thanks.

Pages: [1]