- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm using atomic operations to implement mutex and cond (i'm currenting using threadpool using posix threads and now need to move to tbb).
For example i'm doing something like this:
Lock_mutex (mutex * m){
while (T&S(TS_Object *) m);
}
Unlock_mutex(mutex *m){
Reset((TS_Object *) m)
}
(this is just pseudo code, the param is actually an atomic operation).My problem is with implementing pthread_cond_wait and pthread_cond_signal
using only T&S or C&S.
Can anyone directs me please?
Thanks in advanced,
Shay.
Link Copied
9 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This is actually the functions for T&S:
T&S (T&S_object * TS)
{
If (TS.flag==false) {
TS.flag = true;
return false;
} else return true;
}
Reset (T&S_object * TS)
{
TS.flag=false;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Real-world condition variables usually block threads. Blocking can't be implemented with atomic operations.
If you need only a toy implementation, then you can implement wait() as unlock-yield-lock, and signal() as no op. No need for atomic operations either.
If you need only a toy implementation, then you can implement wait() as unlock-yield-lock, and signal() as no op. No need for atomic operations either.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the really fast reply,
i'm not familiar with unlock-yield-lock, can you link me to a code example maybe?
and also, how can i signal other threads in my threadpool that a job is done if i made this function no op?
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
> i'm not familiar with unlock-yield-lock, can you link me to a code example maybe?
void condvar_wait(mutex* m)
{
Unlock_mutex(m);
pthread_yield()/SwitchToThread();
Lock_mutex(m);
}
void condvar_signal/broadcast()
{
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
> and also, how can i signal other threads in my threadpool that a job is done if i made this function no op?
Since threads are not blocked, there is no need to signal them - they are always ready notice any state change.
Since threads are not blocked, there is no need to signal them - they are always ready notice any state change.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Excellent, thanks a lot.
Is there anequivalent for pthread_yield in tbb's library?
or i should implement one myself?
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting shay86
Excellent, thanks a lot.
Is there anequivalent for pthread_yield in tbb's library?
or i should implement one myself?
Thanks.
tbb::this_tbb_thread::yield() in
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Has anyone tried emulating condition variables with dummy child tasks and continuations?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
don't you want to use tbb's condition variable?
--Vladimir

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page