just::thread Support Forum
September 09, 2010, 10:33:23 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: just::thread V1.4.1 for Windows and Linux Released
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Just a few questions  (Read 1550 times)
CharlesB
Beta Testers
Newbie
Posts: 1


View Profile
« on: October 16, 2008, 10:25:35 AM »

Hello,

I would like to know where I can find examples of the library? I found that the Thread Library Working Draft can be a good starting point, maybe it is worth mentionning it?

CharlesB
Logged
Anthony Williams
Administrator
Newbie
Posts: 46



View Profile WWW
« Reply #1 on: October 16, 2008, 01:42:05 PM »

There are some examples in my introduction to the C++0x thread library on DevX: http://www.devx.com/SpecialReports/Article/38883

Here's a simple example program that launches two threads:

Code:
#include <thread>
#include <mutex>
#include <iostream>
#include <chrono>

std::mutex iom;

void thread_func(int id)
{
    for(unsigned i=0;i<1000;++i)
    {
        std::this_thread::sleep_for(std::chrono::milliseconds(1));
       
        std::lock_guard<std::mutex> lk(iom);
        std::cout<<"Thread "<<id<<" ";
    }
}


int main()
{
    std::thread t1(thread_func,1);
    std::thread t2(thread_func,2);
    t2.join();
    t1.join();
}
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!