Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 311621 Details for
Bug 455088
[ia64] strace -f crashes multhreaded program
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
Simple threading testcase.
threadit.cpp (text/plain), 3.76 KB, created by
Jan Kratochvil
on 2008-07-11 21:20:22 UTC
(
hide
)
Description:
Simple threading testcase.
Filename:
MIME Type:
Creator:
Jan Kratochvil
Created:
2008-07-11 21:20:22 UTC
Size:
3.76 KB
patch
obsolete
>// >// Count the number of lines in a number of files. >// Illustrates use of multithreading. Note: run this program >// several times to see how the threads get scheduled on the system. >// Scheduling will be different each time since the system has lots >// of threads running, which we do not see and these will affect the >// scheduling of our program. >// >// Note that, on a multiprocessor system, this program has a potential >// race condition to update the shared variable LINECOUNT, so we >// must use a mutex to make a short critical section whenever accessing >// this shared variable. >// >// This program uses POSIX threads (pthreads) >// >/////////////////////////////////////////////////////////////////////// > >#include <iostream.h> >#include <fstream.h> >#include <pthread.h> >#include <sched.h> > >const int bufsize = 100; >const int maxfiles = 4; > >void *ParseFile(void *); // Must be void *, defined in pthread.h ! > >int LINECOUNT = 0; > >/**********************************************************************/ > >main () > >{ pthread_t tid[maxfiles];; > int i,ret; > >// Create a thread for each file > >ret = pthread_create(&(tid[0]), NULL, ParseFile, (void*) "proc1"); >ret = pthread_create(&(tid[1]), NULL, ParseFile, (void*) "proc2"); >sleep(10); >ret = pthread_create(&(tid[2]), NULL, ParseFile, (void*) "proc3"); >ret = pthread_create(&(tid[3]), NULL, ParseFile, (void*) "proc4"); >sleep(1); >ret = pthread_create(&(tid[2]), NULL, ParseFile, (void*) "proc5"); >ret = pthread_create(&(tid[3]), NULL, ParseFile, (void*) "proc6"); >sleep(1); >ret = pthread_create(&(tid[2]), NULL, ParseFile, (void*) "proc7"); >ret = pthread_create(&(tid[3]), NULL, ParseFile, (void*) "proc8"); >sleep(1); >ret = pthread_create(&(tid[2]), NULL, ParseFile, (void*) "proc9"); >ret = pthread_create(&(tid[3]), NULL, ParseFile, (void*) "proc10"); >sleep(1); >ret = pthread_create(&(tid[2]), NULL, ParseFile, (void*) "proc11"); >ret = pthread_create(&(tid[3]), NULL, ParseFile, (void*) "proc12"); > >ret = pthread_create(&(tid[0]), NULL, ParseFile, (void*) "proc1"); >ret = pthread_create(&(tid[1]), NULL, ParseFile, (void*) "proc2"); >sleep(10); >ret = pthread_create(&(tid[2]), NULL, ParseFile, (void*) "proc3"); >ret = pthread_create(&(tid[3]), NULL, ParseFile, (void*) "proc4"); >sleep(1); >ret = pthread_create(&(tid[2]), NULL, ParseFile, (void*) "proc5"); >ret = pthread_create(&(tid[3]), NULL, ParseFile, (void*) "proc6"); >sleep(1); >ret = pthread_create(&(tid[2]), NULL, ParseFile, (void*) "proc7"); >ret = pthread_create(&(tid[3]), NULL, ParseFile, (void*) "proc8"); >sleep(1); >ret = pthread_create(&(tid[2]), NULL, ParseFile, (void*) "proc9"); >ret = pthread_create(&(tid[3]), NULL, ParseFile, (void*) "proc10"); >sleep(1); >ret = pthread_create(&(tid[2]), NULL, ParseFile, (void*) "proc11"); >ret = pthread_create(&(tid[3]), NULL, ParseFile, (void*) "proc12"); > >cout << "Parent thread waiting...\n"; > > // If we don't wait for the threads, they will be killed > // before they can start... > >for (i = 0; i < maxfiles; i++) > { > ret = pthread_join(tid[i],(void **)NULL); > } > >sleep(30); >cout << "Parent thread continuing\n"; >cout << "Number of lines = " << LINECOUNT << endl; >} > >/**********************************************************************/ > >void *ParseFile(void *filename) > >{ fstream file; > char buffer[bufsize]; > pthread_mutex_t mutex; > int ret; > >cout << "Trying to open " << filename << endl; > >file.open((char *)filename, ios::in); > >if (! file) > { > cerr << "Couldn't open file\n"; > return NULL; > } > >while (!file.eof()) > { > file.getline(buffer,bufsize); > cout << filename << ":" <<buffer << endl; > > // Critical section > > ret = pthread_mutex_lock(&mutex); > LINECOUNT++; > ret = pthread_mutex_unlock(&mutex); > > // Try uncommenting this .... > // Yield the process, to allow next thread to be run > // sched_yield(); > } > >file.close(); >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 455088
:
311621
|
313210