TEST_F(DriverConductorNetworkTest, shouldBeAbleToAddAndRemoveSingleNetworkSubscription) { int64_t client_id = nextCorrelationId(); int64_t sub_id = nextCorrelationId(); int64_t remove_correlation_id = nextCorrelationId(); ASSERT_EQ(addNetworkSubscription(client_id, sub_id, CHANNEL_1, STREAM_ID_1, -1), 0); doWork(); EXPECT_EQ(aeron_driver_conductor_num_network_subscriptions(&m_conductor.m_conductor), 1u); EXPECT_EQ(readAllBroadcastsFromConductor(null_handler), 1u); ASSERT_EQ(removeSubscription(client_id, remove_correlation_id, sub_id), 0); doWork(); auto handler = [&](std::int32_t msgTypeId, AtomicBuffer& buffer, util::index_t offset, util::index_t length) { ASSERT_EQ(msgTypeId, AERON_RESPONSE_ON_OPERATION_SUCCESS); const command::OperationSucceededFlyweight response(buffer, offset); EXPECT_EQ(response.correlationId(), remove_correlation_id); }; EXPECT_EQ(aeron_driver_conductor_num_network_subscriptions(&m_conductor.m_conductor), 0u); EXPECT_EQ(readAllBroadcastsFromConductor(handler), 1u); }
TEST_F(DriverConductorNetworkTest, shouldBeAbleToTimeoutReceiveChannelEndpointWithClientKeepaliveAfterRemoveSubscription) { int64_t client_id = nextCorrelationId(); int64_t sub_id = nextCorrelationId(); int64_t remove_correlation_id = nextCorrelationId(); ASSERT_EQ(addNetworkSubscription(client_id, sub_id, CHANNEL_1, STREAM_ID_1, false), 0); doWork(); EXPECT_EQ(aeron_driver_conductor_num_network_subscriptions(&m_conductor.m_conductor), 1u); ASSERT_EQ(removeSubscription(client_id, remove_correlation_id, sub_id), 0); doWork(); EXPECT_EQ(readAllBroadcastsFromConductor(null_handler), 2u); int64_t timeout = m_context.m_context->client_liveness_timeout_ns; doWorkUntilTimeNs( timeout, 100, [&]() { clientKeepalive(client_id); }); EXPECT_EQ(aeron_driver_conductor_num_clients(&m_conductor.m_conductor), 1u); EXPECT_EQ(aeron_driver_conductor_num_network_subscriptions(&m_conductor.m_conductor), 0u); EXPECT_EQ(aeron_driver_conductor_num_receive_channel_endpoints(&m_conductor.m_conductor), 0u); }
TEST_F(DriverConductorNetworkTest, shouldRemoveSubscriptionAfterImageTimeout) { int64_t client_id = nextCorrelationId(); int64_t sub_id = nextCorrelationId(); int64_t remove_correlation_id = nextCorrelationId(); ASSERT_EQ(addNetworkSubscription(client_id, sub_id, CHANNEL_1, STREAM_ID_1, -1), 0); doWork(); aeron_receive_channel_endpoint_t *endpoint = aeron_driver_conductor_find_receive_channel_endpoint( &m_conductor.m_conductor, CHANNEL_1); createPublicationImage(endpoint, STREAM_ID_1, 1000); int64_t timeout = m_context.m_context->image_liveness_timeout_ns + (m_context.m_context->client_liveness_timeout_ns * 2); doWorkUntilTimeNs( timeout, 100, [&]() { clientKeepalive(client_id); }); EXPECT_EQ(readAllBroadcastsFromConductor(null_handler), 3u); EXPECT_EQ(aeron_driver_conductor_num_images(&m_conductor.m_conductor), 0u); EXPECT_EQ(aeron_driver_conductor_num_active_network_subscriptions(&m_conductor.m_conductor, CHANNEL_1, STREAM_ID_1), 0u); ASSERT_EQ(removeSubscription(client_id, remove_correlation_id, sub_id), 0); doWork(); doWork(); EXPECT_EQ(aeron_driver_conductor_num_network_subscriptions(&m_conductor.m_conductor), 0u); }
TEST_F(DriverConductorNetworkTest, shouldRemoveSubscriptionFromImageWhenRemoveSubscription) { int64_t client_id = nextCorrelationId(); int64_t sub_id = nextCorrelationId(); ASSERT_EQ(addNetworkSubscription(client_id, sub_id, CHANNEL_1, STREAM_ID_1, -1), 0); doWork(); EXPECT_EQ(readAllBroadcastsFromConductor(null_handler), 1u); aeron_receive_channel_endpoint_t *endpoint = aeron_driver_conductor_find_receive_channel_endpoint( &m_conductor.m_conductor, CHANNEL_1); createPublicationImage(endpoint, STREAM_ID_1, 1000); EXPECT_EQ(aeron_driver_conductor_num_images(&m_conductor.m_conductor), 1u); aeron_publication_image_t *image = aeron_driver_conductor_find_publication_image(&m_conductor.m_conductor, endpoint, STREAM_ID_1); EXPECT_NE(image, (aeron_publication_image_t *)NULL); EXPECT_EQ(aeron_publication_image_num_subscriptions(image), 1u); int64_t remove_correlation_id = nextCorrelationId(); ASSERT_EQ(removeSubscription(client_id, remove_correlation_id, sub_id), 0); doWork(); EXPECT_EQ(aeron_publication_image_num_subscriptions(image), 0u); EXPECT_EQ(readAllBroadcastsFromConductor(null_handler), 2u); }
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int cmdShow) { StringVector sv = Helper::split(lpCmdLine, '-'); bool minimized = false; for (StringVector::iterator itr = sv.begin(); itr != sv.end(); ++ itr) { if (*itr == "minimized" || *itr == "m") { minimized = true; break; } } if (minimized) { return doWork(); } else { if(AllocConsole()) { freopen("CONOUT$", "w", stdout); SetConsoleTitle(SERVER_APP_NAME); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED); } outbuf ob; std::streambuf *sb = std::cout.rdbuf(&ob); int result = doWork(); std::cout.rdbuf(sb); return result; } }
TEST_F(DriverConductorNetworkTest, shouldKeepSubscriptionMediaEndpointUponRemovalOfAllButOneSubscriber) { int64_t client_id = nextCorrelationId(); int64_t sub_id_1 = nextCorrelationId(); int64_t sub_id_2 = nextCorrelationId(); int64_t sub_id_3 = nextCorrelationId(); int64_t sub_id_4 = nextCorrelationId(); ASSERT_EQ(addNetworkSubscription(client_id, sub_id_1, CHANNEL_1, STREAM_ID_1, -1), 0); ASSERT_EQ(addNetworkSubscription(client_id, sub_id_2, CHANNEL_1, STREAM_ID_2, -1), 0); ASSERT_EQ(addNetworkSubscription(client_id, sub_id_3, CHANNEL_1, STREAM_ID_3, -1), 0); ASSERT_EQ(addNetworkSubscription(client_id, sub_id_4, CHANNEL_1, STREAM_ID_4, -1), 0); doWork(); int64_t remove_correlation_id_1 = nextCorrelationId(); int64_t remove_correlation_id_2 = nextCorrelationId(); int64_t remove_correlation_id_3 = nextCorrelationId(); ASSERT_EQ(removeSubscription(client_id, remove_correlation_id_1, sub_id_1), 0); ASSERT_EQ(removeSubscription(client_id, remove_correlation_id_2, sub_id_2), 0); ASSERT_EQ(removeSubscription(client_id, remove_correlation_id_3, sub_id_3), 0); doWork(); aeron_receive_channel_endpoint_t *endpoint = aeron_driver_conductor_find_receive_channel_endpoint( &m_conductor.m_conductor, CHANNEL_1); ASSERT_NE(endpoint, (aeron_receive_channel_endpoint_t *)NULL); ASSERT_EQ(aeron_driver_conductor_num_receive_channel_endpoints(&m_conductor.m_conductor), 1u); ASSERT_EQ(aeron_driver_conductor_num_network_subscriptions(&m_conductor.m_conductor), 1u); EXPECT_EQ(readAllBroadcastsFromConductor(null_handler), 7u); }
TEST_F(DriverConductorNetworkTest, shouldBeAbleToAddSingleNetworkPublication) { int64_t client_id = nextCorrelationId(); int64_t pub_id = nextCorrelationId(); ASSERT_EQ(addNetworkPublication(client_id, pub_id, CHANNEL_1, STREAM_ID_1, false), 0); doWork(); aeron_send_channel_endpoint_t *endpoint = aeron_driver_conductor_find_send_channel_endpoint( &m_conductor.m_conductor, CHANNEL_1); ASSERT_NE(endpoint, (aeron_send_channel_endpoint_t *)NULL); aeron_network_publication_t *publication = aeron_driver_conductor_find_network_publication( &m_conductor.m_conductor, pub_id); ASSERT_NE(publication, (aeron_network_publication_t *)NULL); auto handler = [&](std::int32_t msgTypeId, AtomicBuffer& buffer, util::index_t offset, util::index_t length) { ASSERT_EQ(msgTypeId, AERON_RESPONSE_ON_PUBLICATION_READY); const command::PublicationBuffersReadyFlyweight response(buffer, offset); EXPECT_EQ(response.streamId(), STREAM_ID_1); EXPECT_EQ(response.correlationId(), pub_id); EXPECT_GT(response.logFileName().length(), 0u); }; EXPECT_EQ(readAllBroadcastsFromConductor(handler), 1u); }
int main() { int x = 10, y = 50, z = 15, sum, max; doWork(x, y, z, &sum, &max); printf("Sum = %d, Max = %d\n", sum, max); return 0; }
bool BlinkyTapeUploader::upgradeFirmware(int timeout) { QByteArray sketch = QByteArray(reinterpret_cast<const char*>(PRODUCTION_DATA),PRODUCTION_LENGTH); bootloaderPollTimeout = timeout; char buff[BUFF_LENGTH]; snprintf(buff, BUFF_LENGTH, "Sketch size: %iB", sketch.length()), qDebug() << buff; // The entire sketch must fit into the available memory, minus a single page // at the end of flash for the configuration header // TODO: Could save ~100 bytes if we let the sketch spill into the unused portion // of the header. if(sketch.length() > FLASH_MEMORY_AVAILABLE) { qDebug() << "sketch can't fit into memory!"; errorString = QString("Sorry! The Pattern is a bit too big to fit in BlinkyTape memory right now. We're working on improving this! Avaiable space=%1, Pattern size=%2") .arg(FLASH_MEMORY_AVAILABLE) .arg(sketch.length()); return false; } // Put the sketch, pattern, and metadata into the programming queue. flashData.push_back(FlashSection(PRODUCTION_ADDRESS, sketch)); setProgress(0); // TODO: Calculate this based on feedback from the programmer. setMaxProgress(300); stateStartTime = QDateTime::currentDateTime(); state = State_WaitForBootloaderPort; bootloaderResetTimer->singleShot(0,this,SLOT(doWork())); return true; }
void Parallel::run(int threadIndex) { while (true) { // Wait for new work in a critical section { std::unique_lock<std::mutex> lock(_mutex); // Indicate that this thread is no longer doing work _active[threadIndex] = false; // Tell the main thread when all parallel threads are inactive if (!threadsActive()) _conditionMain.notify_all(); // Wait for new work while (true) { _conditionExtra.wait(lock); // Check for termination request (don't bother with _active; it's no longer used) if (_terminate) return; // Check that we actually have new work if (_active[threadIndex]) break; } } // Do work as long as some is available doWork(); } }
TEST_F(DriverConductorNetworkTest, shouldBeAbleToTimeoutNetworkSubscription) { int64_t client_id = nextCorrelationId(); int64_t sub_id = nextCorrelationId(); ASSERT_EQ(addNetworkSubscription(client_id, sub_id, CHANNEL_1, STREAM_ID_1, false), 0); doWork(); EXPECT_EQ(aeron_driver_conductor_num_receive_channel_endpoints(&m_conductor.m_conductor), 1u); EXPECT_EQ(aeron_driver_conductor_num_network_subscriptions(&m_conductor.m_conductor), 1u); EXPECT_EQ(readAllBroadcastsFromConductor(null_handler), 1u); doWorkUntilTimeNs( m_context.m_context->publication_linger_timeout_ns + (m_context.m_context->client_liveness_timeout_ns * 2)); EXPECT_EQ(aeron_driver_conductor_num_clients(&m_conductor.m_conductor), 0u); EXPECT_EQ(aeron_driver_conductor_num_network_subscriptions(&m_conductor.m_conductor), 0u); EXPECT_EQ(aeron_driver_conductor_num_receive_channel_endpoints(&m_conductor.m_conductor), 0u); auto handler = [&](std::int32_t msgTypeId, AtomicBuffer& buffer, util::index_t offset, util::index_t length) { ASSERT_EQ(msgTypeId, AERON_RESPONSE_ON_CLIENT_TIMEOUT); const command::ClientTimeoutFlyweight response(buffer, offset); EXPECT_EQ(response.clientId(), client_id); }; EXPECT_EQ(readAllBroadcastsFromConductor(handler), 1u); }
//COnstructor MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); //Server object ser = new Server(); //THread for server m_thread = new QThread; //Connection to signal the server class to start working and checking for messages connect(this, SIGNAL(startServer()), ser, SLOT(doWork())); //Connection to notify the GUI to update connect(ser, SIGNAL(sendText(QString)), this, SLOT(writeText(QString))); //Start the thread ser->moveToThread(m_thread); m_thread->start(); //Start the server working to check for messages emit startServer(); }
int db2_access(test_req_t *req, test_req_t *resp) { SQLHENV henv; /* environment handle */ SQLHDBC hdbc; /* connection handle */ SQLRETURN rc = SQL_ERROR; SQLHSTMT shdl; btlogger_debug("op=%c data=%s db=%s\n", req->op, req->data, req->db); if (init(req->db, &henv, &hdbc) != SQL_SUCCESS) return (int) rc; rc = SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &shdl); if ( rc != SQL_SUCCESS ) { (void) check_error(SQL_HANDLE_STMT, shdl, rc, "SQLAllocHandle", (SQLCHAR *) "statement handle"); } else { rc = doWork(req->op, req->data, henv, hdbc, shdl, resp); (void) SQLFreeStmt(shdl, SQL_DROP); } fini(henv, hdbc); return (int) rc; }
void loop() { // do housekeeping doWork(); // character received on serial port? may be a connection attempt if (Serial.available() > 0) { // indicate connected status digitalWrite(13, HIGH); // set the LED on // start the OPDI protocol, passing a pointer to the housekeeping function // this call blocks until the slave is disconnected uint8_t result = Opdi->start(&doWork); // no regular disconnect? if (result != OPDI_DISCONNECTED) { digitalWrite(13, LOW); // set the LED off delay(500); // flash error code on LED for (uint8_t i = 0; i < result; i++) { digitalWrite(13, HIGH); // set the LED on delay(200); // wait digitalWrite(13, LOW); // set the LED off delay(200); // wait } } digitalWrite(13, LOW); // set the LED off } }
HtmlParser::HtmlParser(const QUrl &url, const QString &text, QObject *parent) : QObject(parent), _info(new UrlInfo, [](UrlInfo* p){delete p;}), _downloaded(false), _text(text), _downloader(nullptr) { _info->_url = url.toString(); _info->_found = false; _info->_status = UrlInfo::DOWNLOADING; _info->_percentage = 0; emit processing(_info.data()); QThread * thread = new QThread(); _downloader = new HtmlDownloader(url); _downloader->moveToThread(thread); connect( thread, SIGNAL(started()), _downloader, SLOT(doWork())); connect( _downloader, SIGNAL(finished(QString)), thread, SLOT(quit())); connect( _downloader, SIGNAL(finished(QString)), this, SLOT(downloaded(QString)), Qt::ConnectionType::DirectConnection); connect(_downloader, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(downloadProgress(qint64,qint64))); connect( thread, SIGNAL(finished()), thread, SLOT(deleteLater())); thread->start(); }
void Worker::onGoFromService (InputParametersRS input) { try { doWork( input); } catch ( Interrupt & ) { // std::cerr << "*** Worker interrupted ***\n"; dbg(1) << "RS interrupted\n"; emit interrupt (); } catch ( std::runtime_error & e) { std::cerr << "Worker runtime-exception: " << e.what() << "\n"; emit error( QString("runtime-exception: %1").arg(e.what())); } catch ( std::exception & e) { std::cerr << "Worker std-exception: " << e.what() << "\n"; emit error( QString("std-exception: %1").arg(e.what())); } catch ( std::string & s) { std::cerr << "Worker exception: " << s << "\n"; emit error( QString("exception: %1").arg(s.c_str())); } catch ( QString & s) { std::cerr << "Worker exception: " << s << "\n"; emit error( QString("exception: %1").arg(s)); } catch ( char * s) { std::cerr << "Worker exception: " << s << "\n"; emit error( QString("exception: %1").arg(s)); } catch (...) { std::cerr << "Worker uncaught exception...\n"; dbg(1) << "Worker uncaught exception\n"; emit error ( "Uncaught exception"); // throw; } }
TEST_F(DriverConductorNetworkTest, shouldBeAbleToAddMultipleNetworkSubscriptionsWithDifferentChannelSameStreamId) { int64_t client_id = nextCorrelationId(); int64_t sub_id_1 = nextCorrelationId(); int64_t sub_id_2 = nextCorrelationId(); int64_t sub_id_3 = nextCorrelationId(); int64_t sub_id_4 = nextCorrelationId(); ASSERT_EQ(addNetworkSubscription(client_id, sub_id_1, CHANNEL_1, STREAM_ID_1, -1), 0); ASSERT_EQ(addNetworkSubscription(client_id, sub_id_2, CHANNEL_2, STREAM_ID_1, -1), 0); ASSERT_EQ(addNetworkSubscription(client_id, sub_id_3, CHANNEL_3, STREAM_ID_1, -1), 0); ASSERT_EQ(addNetworkSubscription(client_id, sub_id_4, CHANNEL_4, STREAM_ID_1, -1), 0); doWork(); aeron_receive_channel_endpoint_t *endpoint_1 = aeron_driver_conductor_find_receive_channel_endpoint( &m_conductor.m_conductor, CHANNEL_1); aeron_receive_channel_endpoint_t *endpoint_2 = aeron_driver_conductor_find_receive_channel_endpoint( &m_conductor.m_conductor, CHANNEL_2); aeron_receive_channel_endpoint_t *endpoint_3 = aeron_driver_conductor_find_receive_channel_endpoint( &m_conductor.m_conductor, CHANNEL_3); aeron_receive_channel_endpoint_t *endpoint_4 = aeron_driver_conductor_find_receive_channel_endpoint( &m_conductor.m_conductor, CHANNEL_4); ASSERT_NE(endpoint_1, (aeron_receive_channel_endpoint_t *)NULL); ASSERT_NE(endpoint_2, (aeron_receive_channel_endpoint_t *)NULL); ASSERT_NE(endpoint_3, (aeron_receive_channel_endpoint_t *)NULL); ASSERT_NE(endpoint_4, (aeron_receive_channel_endpoint_t *)NULL); ASSERT_EQ(aeron_driver_conductor_num_receive_channel_endpoints(&m_conductor.m_conductor), 4u); ASSERT_EQ(aeron_driver_conductor_num_network_subscriptions(&m_conductor.m_conductor), 4u); EXPECT_EQ(readAllBroadcastsFromConductor(null_handler), 4u); }
void OscListenerWorker::Start() { if (!running) { running = true; doWork(); } }
void createProc(int number, pid_t* pid_array){ int i = 0; pid_t pid; int *array; //Preparing random order squence array = (int*)malloc(sizeof(int)*number); for(i = 0; i < number; ++i) array[i] = i; shuffle(array, number); unlockSem(0); //aby mohol prvy bezat for(i = 0; i < number; ++i){ switch(pid = fork()){ case 0: doWork(array[i], getNext(array, i + 1, number)); exit(EXIT_SUCCESS); case -1: perror("fork"); exit(EXIT_FAILURE); default: pid_array[i] = pid; break; } } free(array); }
void QuebrarSenha::quebrarSenhaZIP() { QString text = ui->lineEdit->text(); QThread *workerThread; CountWorker *worker; int i; //Esta é a parte mais importante do programa; //Está sendo criado 4 threads, onde cada thread é responsável por executar uma porção das senhas em paralelo //As senhas variam de 0 a 500000 for(i = 0; i < 4; i++){ workerThread = new QThread; QLabel *label; if(i==0) label=ui->thread0; else if(i==1) label=ui->thread1; else if(i==2) label=ui->thread2; else if(i==3) label=ui->thread3; worker = new CountWorker(i*125000, (i+1)*125000, text, label); worker->moveToThread(workerThread); connect(workerThread, SIGNAL(started()), worker, SLOT(doWork())); connect(worker, SIGNAL(finished()), workerThread, SLOT(quit())); connect(worker, SIGNAL(finished()), worker, SLOT(deleteLater())); connect(workerThread, SIGNAL(finished()), workerThread, SLOT(deleteLater())); connect(worker, SIGNAL(updateCount(int, QLabel*)), this, SLOT(updateCount(int, QLabel*))); connect(worker, SIGNAL(updateSenha(int)), this, SLOT(updateSenha(int))); connect(worker, SIGNAL(updateProgressBar(float)), this, SLOT(updateProgressBar(float))); workerThread->start(); } }
//======== // main() //======== int main(int argc, char** argv) { bool isok = false; try { Input input(argc, argv); doWork(input); isok = true; } catch(const Help& h) { std::cout << prognm << std::endl; std::cout << " citation: " + citation << std::endl; std::cout << " version: " + version << std::endl; std::cout << " authors: " + authors << std::endl; std::cout << usage() << std::endl; isok = true; } catch(const Version& v) { std::cout << prognm << std::endl; std::cout << " citation: " + citation << std::endl; std::cout << " version: " + version << std::endl; std::cout << " authors: " + authors << std::endl; isok = true; } catch(std::string& msg) { std::cerr << prognm << std::endl; std::cerr << " citation: " + citation << std::endl; std::cerr << " version: " + version << std::endl; std::cerr << " authors: " + authors << std::endl; std::cerr << usage() << std::endl; std::cerr << msg << std::endl; } catch(std::exception& e) { std::cerr << usage() << std::endl; std::cerr << e.what() << std::endl; } catch(...) { std::cerr << usage() << std::endl; std::cerr << "Unknown Error. Aborting" << std::endl; } return(isok ? EXIT_SUCCESS : EXIT_FAILURE); }
TEST_F(DriverConductorNetworkTest, shouldBeAbleToAddSingleNetworkSubscription) { int64_t client_id = nextCorrelationId(); int64_t sub_id = nextCorrelationId(); ASSERT_EQ(addNetworkSubscription(client_id, sub_id, CHANNEL_1, STREAM_ID_1, -1), 0); doWork(); aeron_receive_channel_endpoint_t *endpoint = aeron_driver_conductor_find_receive_channel_endpoint( &m_conductor.m_conductor, CHANNEL_1); ASSERT_NE(endpoint, (aeron_receive_channel_endpoint_t *)NULL); auto handler = [&](std::int32_t msgTypeId, AtomicBuffer& buffer, util::index_t offset, util::index_t length) { ASSERT_EQ(msgTypeId, AERON_RESPONSE_ON_SUBSCRIPTION_READY); const command::SubscriptionReadyFlyweight response(buffer, offset); EXPECT_EQ(response.correlationId(), sub_id); }; EXPECT_EQ(readAllBroadcastsFromConductor(handler), 1u); }
void Compute::receiveB(int indexX, float *data, int size) { for(int j=0; j<subBlockDimYx; j++) for(int k=0; k<blockDimZ; k++) B[indexX*subBlockDimYx*blockDimZ + j*blockDimZ + k] = data[j*blockDimZ + k]; countB++; if(countA == num_chare_z-1 && countB == num_chare_x-1) doWork(); }
void Compute::receiveA(int indexZ, float *data, int size) { for(int i=0; i<subBlockDimXz; i++) for(int j=0; j<blockDimY; j++) A[indexZ*subBlockDimXz*blockDimY + i*blockDimY + j] = data[i*blockDimY + j]; countA++; if(countA == num_chare_z-1 && countB == num_chare_x-1) doWork(); }
Scheduler::Scheduler() { reload(); connect(&m_timer, SIGNAL(timeout()), this, SLOT(doWork())); m_timer.start(60*1000); m_instance = this; }
void SFTWorker::run() { assert(m_pCT); while (true) { uint32 status = m_pCT->getStatus(m_uiId); int32 res = BZ_OK; while (status == BaseMCFThread::SF_STATUS_PAUSE) { gcSleep(500); status = m_pCT->getStatus(m_uiId); } if (status == BaseMCFThread::SF_STATUS_STOP) { break; } else if (status == BaseMCFThread::SF_STATUS_NULL) { if (!newTask()) gcSleep(500); continue; } else if (status == BaseMCFThread::SF_STATUS_ENDFILE) { do { res = doWork(); if (bzErrorCheck(res)) break; } while (res != BZ_STREAM_END); } else if (status == BaseMCFThread::SF_STATUS_CONTINUE) { res = doWork(); bzErrorCheck(res); } if (res == BZ_STREAM_END || status == BaseMCFThread::SF_STATUS_SKIP) finishFile(); } }
int main (int argc, char** argv) { MPI_Init (&argc, &argv); int numprocs; MPI_Comm_size (MPI_COMM_WORLD, &numprocs); int myid; MPI_Comm_rank (MPI_COMM_WORLD, &myid); printf ("Hello World from processor: %d out of %d\n", myid, numprocs); int namelen; char myname[MPI_MAX_PROCESSOR_NAME]; MPI_Get_processor_name (myname, &namelen); printf ("processor id=%d, name=%s\n", myid, myname); double time = MPI_Wtime (); double d = doWork (1e7); time = MPI_Wtime() - time; printf ("Time taken by proc = %d is = %g\n", myid, time); printf("processor %d sending its time to proc 0\n", myid); MPI_Send (&time, 1, MPI_DOUBLE, 0, myid, MPI_COMM_WORLD); double totalTime = 0; double recvTime; if (myid == 0) { int i; MPI_Status status; for (i = 0; i < numprocs; ++i) { MPI_Recv (&recvTime, 1, MPI_DOUBLE, i, i, MPI_COMM_WORLD, &status); totalTime += recvTime; printf ("received time = %g from proc = %d\n", recvTime, i); } printf ("time taken, total = %g, avg=%g\n", totalTime, (totalTime/numprocs)); // proc 0 sends the average time to everyone double avgTime = totalTime / numprocs; for (i = 0; i < numprocs; ++i) { printf ("Proc 0 sending avgTime to proc = %d\n", i); MPI_Send (&avgTime, 1, MPI_DOUBLE, i, i, MPI_COMM_WORLD); } } // end if proc 0 double avgTime; MPI_Status status; MPI_Recv (&avgTime, 1, MPI_DOUBLE, 0, myid, MPI_COMM_WORLD, &status); printf ("Proc = %d received average time = %g, from proc 0\n", myid, avgTime); MPI_Finalize (); }
PingThread::PingThread(QObject * const parent, QString *host) : QObject(parent), process(NULL), timer(new QTimer(this)), host(*host) { this->lastPing = std::numeric_limits<float>::quiet_NaN(); startProcess(); connect(timer, SIGNAL(timeout()), this, SLOT(doWork())); timer->start(1000); qDebug() << "thread started"; }
void *rcrtoolDaemon(void* arg) { qthread_worker_t *me_worker = (qthread_worker_t *)(swinfo.worker); qthread_shepherd_t *me = (qthread_shepherd_t *)me_worker->shepherd; if (swinfo.qaffinity && (me->node != -1)) { qt_affinity_set(me_worker,swinfo.nworkerspershep); } doWork(swinfo.nshepherds, swinfo.nworkerspershep); return 0; }
void runProcess() // executes on one thread { size_t start = 0; size_t end = 50LL * 1000LL * 1000LL; bool needLock = false; v.reserve(end); doWork(start, end, needLock); }