tags:

views:

73

answers:

2

Hello

Is there smth like pthread_barrier in SMP Linux kernel?

When kernel works simultaneously on 2 and more CPUs with the same structure, the barrier (like pthread_barrier) can be useful. It will stop all CPUs entering to it until last CPU will run the barrier. From this moment all CPUs again works.

+1  A: 

I'm not familiar with the pthread_barrier() construct, but the kernel has a large number of options for memory barriers.

See lxr memory barriers for the documentation

If you're trying to force a set of threads to wait for each other, you can probably hack something together with mutexes and/or waitqueues - though I'm not sure when you'd want to do that. When do you ever want threads to wait on each other? I am very curious now...

Sam Post
not memory barrier (wmb, mb,rmb), but a synhro barrier
osgx
but thnx for lxr mem bar link.
osgx
+3  A: 

You can probably get equivalent behavior using a completion:

struct fake_barrier_t {
  atomic_t count;
  struct completion comp;
}

/* run before each pass */
void initialize_fake_barrier(struct fake_barrier_t* b)
{
  atomic_set(&b->count, 0);
  init_completion(&b->comp);
}

/* make all tasks sleep until nth arrives, then wake all. */
void fake_barrier(struct fake_barrier_t* b, int n)
{
  if (atomic_inc_return(&b->count) < n)
    wait_for_completion(&b->comp);
  else
    complete_all(&b->comp);
}
Eric Seppanen
+1 great answer. I was thinking something like this but you actually implemented it.
Sam Post