Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- /*
- * File: main.cpp
- * Author: student
- *
- * Created on 2 marca 2018, 12:19
- */
- #include <stdlib.h>
- #include <iostream>
- #include <boost/thread/thread.hpp>
- using namespace std;
- using namespace boost;
- /*
- *
- */
- const int liczbaWatkow = 5;
- const int znakowDoZapisania = 1024;
- const int opoznienie = 100;
- //int licznik = 50;
- mutex licznikMutex;
- class Watek{
- private:
- char znak;
- string &lancuch;
- public:
- Watek(char znak, string& lancuch) :
- znak(znak), lancuch(lancuch) {
- }
- void operator()(){
- lock_guard<mutex> blokada(licznikMutex);
- for (int i = 0 ; i < znakowDoZapisania ; ++i){
- this_thread::sleep_for(chrono::microseconds (opoznienie));
- lancuch[i] = znak;
- }
- }
- };
- int main(int argc, char** argv) {
- string lancuch;
- lancuch.resize(znakowDoZapisania);
- thread_group watki;
- for (int i = 0 ; i< liczbaWatkow ; i++){
- watki.create_thread(Watek('a' + i, lancuch));
- }
- watki.join_all();
- cout << lancuch << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement