- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi All,
I'm a grad student and I have difficulties in implementing critical section and locks in cilkplus. I used cilkplus on the latest gcc. Could someone plese put a simple pseudocode along with the header files that have to be used for critical section and locks, so that I can understnad & implement using my code. Thanks.
Regards,
Sushek Shekar.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The limitation to be aware of is that there are no guarantees about which thread your code is working on at any spawn or sync boundary. CRITICAL_SECTIONs on Windows an mutexes on Linux require the release to be on the same thread as the acquire.
The Cilkscreen tool should issue an error or warning if you're holding a lock at spawn or sync boundary. You can download if from the Cilk Plus website at the http://cilkplus.org/download page.
- Barry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Barry Tannenbaum (Intel) wrote:
...mutexes on Linux require the release to be on the same thread as the acquire.
Does that limitation hold for spinlocks or semaphores? At the very least, you could implement your own spinlock using gcc's built-in compare-and-swap routine. A semaphore would be a better choice if you want blocked threads to go to sleep.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It probably holds for semaphores, though of course you should check the OS documentation to be sure.
It won't hold for spinlocks, but be aware that the Cilk runtime has its own locks, and holding any kind of lock across a spawn or sync boundary runs the risk of lock order inversion which can lead to a deadlock.
- Barry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the reply.
Consider,
cilk_for (int j=0; j<innerreps/nthreads; j++){
delay(delaylength);
}
1. The function delay(delaylength) has to be implemented in the critical section. How do I use mutexes there?
2. I used #include<cilk_mutex.h> in the header, it says, no such file or directory exists. I did check going back to the insatllation files, there's a file called cilk_mutex.h. but #include<cilk.h> is working fine.
thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
cilk_mutex.h was provided by cilk++, a prior implementation of Cilk that's no longer supported. cilk_mutex provided a thin wrapper around a pthread_mutex_t. We withdrew the feature because it's provided by other tools, like tbb and the new C++ standard.
You can use any locking mechanism supported by your OS. Wikipedia has a reasonable introduction to critical sections: http://en.wikipedia.org/wiki/Critical_section . However, keep my warning about holding a lock across a spawn or sync boundary in mind. You'll be safe as long as you acquire and release the lock to within the cilk_for loop body.
Note that you can frequently avoid using locks by using reducers, and reducers have some very nice properties that aren't possible with locks. But that's probably the next topic to be covered, once you've got your locks working. :o)
- Barry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks a lot for the reply. It helped me a lot. Will get back if I have any doubts/questions.
Regards,
Sushek Shekar.

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