Пример #1
0
int main()
{
	msgId = msgget( IPC_PRIVATE, IPC_CREAT | 0600 );	//! Создание очереди сообщений
	if ( msgId == -1 )
		error( "Can't create the message queue." );
	semId = semget( IPC_PRIVATE, 4, IPC_CREAT | 0600 ); //! Создаем набор из 4-х семафоров
	if ( semId == -1 )
		error( "Can't create the semaphores." );

	union sem semun;   //!< Семафоры

	for ( int i = 0; i < 4; i++ ) {
		semun.val = 0; //! начальное значение семафора
		semctl( semId, i, SETVAL, semun );
	}

	poemFileId = open( "poem.txt", O_RDONLY ); //! открываем файл со стихотворением
	if ( poemFileId == -1 )
		error( "Can't open the file" );

	v( semId, 0 ); //! открываем первый семафор
	for ( int i = 0; i < 3; i++ ) {
		int pid = fork();
		if ( pid == 0 )
			processWork( i, semId );
		else if ( pid == -1 )
			error( "Can't create a process." );
	}

	int pid = fork();
	if ( pid == 0 )
		processWork( 3, semId );
	else if ( pid == -1 )
		error( "Can't create a process." );
	else {
		int status;
		//! Ожидаем завершения работы прцоессов-потомков
		for ( int i = 0; i < 4; ++i )
			wait( &status );

		//! Чтение стихотворения
		struct message msg;
		while ( 1 ) {
			//! Получаем следующую строку из очереди
			if ( msgrcv( msgId, &msg, sizeof( struct message ), 1, IPC_NOWAIT ) == -1 )
				break;
			printf( "%s\n", msg.mtext );
		}
		closeIpc(); //! Закрываем семафоры и очередь
	}
	return 0;
}
Пример #2
0
int main()
{
    WorkQueue workQueue; //A work queue that stores functions that take an int and return an int.

    workQueue.push_back(std::bind(add, 2, std::placeholders::_1)); //Use add above to add 2 
    workQueue.push_back(std::bind(divide, 1000, std::placeholders::_1)); //divided 1000 by x
    workQueue.push_back(std::bind(power, 2, std::placeholders::_1)); //2 ^x
    workQueue.push_back(std::bind(mod, std::placeholders::_1, 0xF));
    workQueue.push_back([](int a) {return multiply(a, 100); });
    workQueue.push_back([](int a) {return divide(0xDEAD, a); });

    std::cout << "Processing 100: " << processWork(workQueue, 100) << "\n";  //should print 142
    std::cout << "Processing 1000: " << processWork(workQueue, 1000) << "\n"; //should print 285
    return 0;
}
Пример #3
0
// Called on loadFinished on WebPage
void TestRunner::maybeDump(bool /*success*/)
{

    // This can happen on any of the http/tests/security/window-events-*.html tests, where the test opens
    // a new window, calls the unload and load event handlers on the window's page, and then immediately
    // issues a notifyDone. Needs investigation.
    if (!m_topLoadingFrame)
        return;

    // It is possible that we get called by windows created from the main page that have finished
    // loading, so we don't ASSERT here. At the moment we do not gather results from such windows,
    // but may need to in future.
    if (sender() != m_topLoadingFrame->page())
        return;

    m_loadFinished = true;
    // as the function is called on loadFinished, the test might
    // already have dumped and thus no longer be active, thus
    // bail out here.
    if (m_hasDumped)
        return;

    WorkQueue::shared()->setFrozen(true); // first complete load freezes the queue for the rest of this test
    if (WorkQueue::shared()->count())
        QTimer::singleShot(0, this, SLOT(processWork()));
    else if (!shouldWaitUntilDone()) {
        emit done();
        m_hasDumped = true;
    }
}
Пример #4
0
void LayoutTestController::maybeDump(bool)
{
    m_topLoadingFrame = 0;
    WorkQueue::shared()->setFrozen(true); // first complete load freezes the queue for the rest of this test

    if (!shouldWaitUntilDone()) {
        if (WorkQueue::shared()->count())
            QTimer::singleShot(0, this, SLOT(processWork()));
        else {
            emit done();
            m_isLoading = false;
        }
    }
}