If we want to use thread specific data in a multithreaded application, how to access those data from another collector thread periodically? Is it possible?
Regards
Ram
|
I want to create a thread in C so that the thread automatically call after two seconds. I am using Visual Studio and Windows platform for development.
How do I get started?
... |
How do we create multiple thread during runtime in C programming language?
If we need to create same amount of thread as specified by the user how do we do it?
... |
Let's say I have: sample.c
int main (...) {
char str*;
get s through user input
test(str);
return 0;
}
void test (str) {
copy str to new ...
|
When we make Detached threads in main.
and supose main exits... do the detached threads keep on going on or do they also exit just like our normal Joinable threads?
|
I am trying to create a multi-thread, jpg rotation program but I am having problems getting g_thread to work.
int processUserRequest (UserRequest *uRequest,
...
|
//----------------------------------------------// A function that represents Thread number 1 WM//----------------------------------------------DWORD WINAPI Thread_no_1( LPVOID S ) { data_files *My_files = (data_files *)(S); HANDLE hStdout = NULL; // Get Handle To screen. Else how will we print? if( (hStdout = GetStdHandle(STD_OUTPUT_HANDLE)) == INVALID_HANDLE_VALUE ) ... |
|
|
|
Hello people, I have to optimize a very slow C program that does some processing on some data from a Db, creating some xml files. It has to work with a fairly large data set and is quite slow. The original programmer used threads for this processing, putting items in input queues that the threads keep checking for, processing and passing ... |
Using a mutex or semaphore is non-preemptive provided you use the OS suppplied functions for working with these objects. That is, a preemptive mutex or semaphore is useless. Indedd, it is the non-preemptive quality that prpvides their value. If you write your own mutex or semaphore code then all bets are off. The OS supplied functions have Ring 0 authority which ... |
|
C++ is a standard for the language and language syntax and the standard libraries. The standard libraries include the C standard library and the STL. No-where with-in the C or C++ standard is there any specification for any sort of threading, there can't be because C and C++ are designed to be used on such a wide range of platforms that ... |
Hi all, I'm converting a Linux program to a Windows program using Visual Studio .NET 2003. The code was written using pthread. I have a "First-chance exception at 0x100084c8 in project.exe: 0xC0000005: Access violation reading location 0x000001dc" error that is causing my program to crash, and all but one thread "has exited with code 0 (0x0)." The one thread (0xfe4) exited ... |
|
|
No it is impossible, by definition multi-threading adds more work for the processor to do, it now has to control scheduling the different threads. You use multi-threading to allow you to run 2 threads of execution that have little or nothing to do with each other asynchronously so that you can write the code of each thread without having to worry ... |
_ Program to find out how many seconds it would take to get to various planets. _ Program to give you percentages based on statistic values how good of a chance you have to win your state lottery. _ Program that divides the screen into equal squares and associates a sound with a click inside each square. _ Program that brute ... |
=?GB2312?B?0rvK18qr?= Hi all, Recently I had a new coworker. There is some dispute between us. The last company he worked for has a special networking programming model. They split the business logic into different modules, and have a dedicated thread for the each module. Modules exchanged info through a in-memory message queue. In my opinion, such a model means very complicated ... |
This is my problem: I have two classes A and B: class A { void methodA(); } class B { void methodB(); struct S { int Size; }; S & getMyStruct(); S MyStruct; } methodA and methodB get executed in two different threads concurrently. They both access the variable Size in the structure MyStruct of type S. methodA gets a reference ... |
P: n/a S James S Stapleton Is volatile necessary anymore? I have a two-thread piece of code I've been testing to figure out what volatile does (fairly simple code, uses pthreads). I have an update thread (variables passed as volatile) and a print thread (one variable volatile, the other, not). There is no difference in the behavior of the volatile and ... |
On 25 May 2008 at 20:15, Aggelidis Nikos wrote: It is a know fact that pthreads share the same address space. I thought that this meant that whatever variable i had in main() before creating a thread, i would be able to use in the thread-itself. Unfortunately threads have different stacks and that means that any local variable of main can't ... |
Here is the code: http://pastebin.com/m4a405e67 One advantage to using a region allocator is that you can usually skip most calls to free. Instead you can merge multiple free calls into a single reset call. Here is simple example: __________________________________________________ _________________ int main(void) { allocator this_allocator; /* create allocator instance with initial region size of 8192 and a low-watermark region count of ... |
P: n/a Stephen J. Bevan Jon Harrop >What collection-intensive tasks? > Symbolic rewriting would make a good benchmark. Here is one: > http://www.lambdassociates.org/studies/study10.htm > Try implementing this using reference counting and we can see how it compares (probably on a trickier rewrite). Replace the arbitrary-precision ints with doubles. The (old) machine I read ... |
Hi, I'm trying to write a piece of code that spawns a thread and prints dots every half second until the thread is finished. Code is something like this: import threading class MyThread ( threading.Thread ): def run ( self ): myLongCommand... import time t = MyThread() t.start() while t.isAlive(): print "." time.sleep(.5) print "OK" The thing is this doesn't print ... |
|
|
hi how to start learning multithreading.Is multithreading related to OS in which program is running. thanks in advance I don't know much about the various techniques but I used pThreads recently for some code which seem to have worked very nicely and the same code runs under both Windows and Linux. You'll also find that if you search for pthreads in ... |
Hi all, I'm having a fun with multi threading programming. My target machine has 8 Intel Xeon CPUs. Working environment is Linux based and using g+ +. Boost library is being used for my fun. My question is is there any possible way to bind a thread to a specific CPU among 8 CPUs? If it is possible would you please ... |
30. Thread bytes.com"Jean-Franois GAZET" wrote in message news:3f478fb6$0$2411$a3f2974a@nnrp1.numericable.fr ...[color=blue] > Hi, > > i'm writing a win32 application. I need the code to : > - start a "win32 console application" (a MSDOS EXE file) > - write to its STDIN > - read from its STDOUT > But with a thread, i think, not to "lock" the main application. > > ... |
Hi, I'm a student working on a report about a piece of software (C++, linux) that I've written. The major tasks that this software executes are: >create a string based on called function (just a couple of integers converted to 'chars') >open a thread (using pthread_create) - main thread: start (deadlock) timer - new thread: execute client functions for (wireless) communication ... |
<- about to have a major crisis here. All I wanted is to create a little tool with a GUI. Now I see problems related to thread programming arising everywhere. If I use the GUI to set a flag as a stop condition checked by my thread, but reset the flag when the user wants to restart the thread, then technically ... |
|
|
|
The following tries to make thread-safe code while avoiding the high cost of a lock. But is it kosher? > > // file or global scope level > int X; volatile _Bool IsInitializedX=false; > > > // thread 1 > X=5; IsInitializedX=true; > > > // thread 2 > while(!IsInitializedX) ; printf("Now safe to read X=%d\n", X); |
Hello, I need a buffer reinitialized approx. once in each second (I think this is quite often). Now I think to do the reinit within a separate thread (I am using boost::thread). Well, filling the buffer is a real short task but must be done very often (at least once in a second). So what is the guide line how often ... |
|
I have software for a BERT that networks with a external database (SMU). The program requests information from the SMU and waits for a response. Sometimes, the software hangs while waiting for the information. To prevent the program from hanging, I decided to create a threading system such that a timer will indicate if the read procedure is hung. If this ... |
Hi I have a HANDLE to an Event, like this.. HANDLE h = ::CreateEvent(NULL, FALSE, FALSE, NULL); This is running in one thread in one class. For example we will call that class as "Class A" Now i want to use this HANDLE in another thread in another class to call SetEvent(h); This is "Class B" I tried creating a pointer ... |
I did modify it by using critical sections, but still the same problem. I don't feel like writing my own rand function. Isn't there anyway to get this done? Not really unless you have a separate thread which serves random numbers to the other threads so that only 1 thread is calling rand. This would be more complecated than writing your ... |
|
|
|
|
|
|
|
|
Hmm.. Actually it is not working fine. I can compile without error message but when running the program I have: " Segmentation fault " ...and the execution stops from a printf("portfd %d\n", (int) portfd )) I can get: portfd = 268513978 supposed to be smth like 1 or 2... I ve got the same 268513978 with : printf("portfd %d\n", (int *) ... |
Hi, I'm writing a background timer using /cc++/thread.h. this is my source code: timer.h ----------------------------------------------- #ifndef TIMER_H #define TIMER_H #include using namespace std; using namespace ost; class Timer : public Thread { private: int timeout; public: Timer(); ~Timer(); void setTimer(float t); void run(); }; #endif timer.cpp ------------------------------------- #include "timer.h" #include Timer::Timer() { } Timer::~Timer() { terminate(); } void Timer::setTimer(float ... |
|
Hi Is there a way to find out if a thread holds a handle to a loaded module? In detail: I have all IDs and handles of all running threads and loaded modules(dlls) of a process. No i want to know which thread uses which module. My target is to make a taskmanager-like tool for WindowsCE. There i have a big ... |
The function f gets variable arguments and creates several threads which each shall receive all of the variable arguments. Like so: void f( my_callback* array_of_callbacks, ...){ va_list va; va_start(va,array_of_callbacks); /* now loop through array */ /* create thread for each callback and pass va for each callback */ /* end of loop */ va_end va; } (1) Is it ok to ... |
I am doing a real time project. In that, I need 4threads to be synchronized each other one after the other. In that i am facing a problem of buffer overwrite. I am using a 2D buffer [10][1000].Once i stored data into it, i signaled the second thread. The problem here is that the first thread signal is missed by the ... |
I'm a total newbie to threads, but am generally good with c. I'm trying to run a program that might take a while, but system by itself does not return until the program is finished. I thought that threads would work, because I could send system to run on a thread then continue with the program. I attempted, but it seems ... |
Hi All, Just illustrating my lack of C knowledge again: Wot now ? cat test.c #include void thread_init( void ){} Wot now ? xlc_r -c -qlanglvl=stdc89 test.c "test.c", line 3.6: 1506-343 (S) Redeclaration of thread_init differs from previous declaration on line 886 of "/usr/include/sys/thread.h". "test.c", line 3.6: 1506-376 (I) Redeclaration of thread_init has a different number of fixed parameters than ... |
Hi All, I'm trying to write a windows service by modifying an example I found at http://www.thecodeproject.com This is my first encounter with a multithreaded app so please forgive this newbie question but I'm having a little bit of difficulty using global variables inside the threads The code basically looks like this HANDLE killServiceEvent; HANDLE hGinaThread, hTrayIconThread; char * szPinNumber; void ... |
luckybalaji@gmail.com Hello, I have searched in group. I didnt get answer for my doubts. So i'm posting this. It is very basic doubt on thread. I wrote below program to start understanding the thread. #include #include #include #include #include extern int errno; ofstream out; void* do_loop(void* data) { int i; int me = *((int*)data); for (i=0; ... |
Dear All, I have a programm in which I am using the thread, Well some times It happens that thread get closed, well I am not able to Figure out exactly when this is happening, (Thread Is Getting Closed) So please let me know some of the senario in which thread will get closed, May be your points may help me ... |
ankur.cdac@gmail.com writes:[color=blue] > The utility fails on an HP-UX 11.23 > machine. When executing the 'crecv' command, a core file is > generated and the following message is printed out: > > Assertion failed: __thread_init == NULL, file > ../../../../../core/libs/libc/shared_pa2_32/../core/threads/pthrea > d_stubs1.c, line 361 > Abort(coredump)[/color] Uh huh. And did you have a question about it? We don't know what the ... |
P: n/a elnanni@gmail.com I've a problem in the use of threads, they don't work as i want them to. Here's the code, the problem is that if i uncomment the //pthread_join(thread_ID, NULL);, the main program stops until the spawned thread is finished, but that's not the intended way, because i need that the opc variable change only when the user pushes ... |
vivekian wrote:[color=blue] > Trying to write an application in linux where two threads share the > same object ( primarily a double linked list ) . How do i implement > such an object ? Or is there a better way to do this ?[/color] This is not really a question for this group since threads are off topic here. However, ... |
Hey Everyone! So I'm working on a homework problem (no direct answers please!), and am looking for some advice/direction. I'm brand new to C, but it's the language we have to use. I implemented the Eratosthenes Sieve with a single-threaded process and it works just fine, but now I need to make it work with two threads. The actual project spec ... |
|
|
|
|
Code: void *ethercat_cyclic_function() { printf( "Starting cyclic thread...\n" ); IO_digIn_t inputs; IO_digOut_t outputs; pthread_t vision_thread_ID; while( 1 ) { time_t now = clock(); time_t limit = now + CYCLE_TIME * CLOCKS_PER_SEC; /******************************** * Update digital inputs * ********************************/ ecrt_master_receive( g_master ); ecrt_domain_process( g_domain ); unsigned char pdo_digIn1 = (unsigned char)EC_READ_U8( g_process_data + g_offInpMod1 ); inputs.pushbutton = pdo_digIn1 >> 1; /******************************** * ... |
Hi, I am a beginner with threads in C. I need help regarding thread management in C. my GNU thread library version is the following: NPTL 2.9 My main program creates a thread. That thread must complete certain tasks before the program terminates. But what happens in most of the cases is that the main program ends without the thread finishing ... |
|
Hello! I'm supposed to write a program forks 3 processes (4 in total, including the father). and then have each process fork three threads and two additional process. These two additional processes will fork three threads as well. You can guess from the unnecessary complexity that this is a class assignment. Anyway, I wrote the following code that displays a string ... |
Audio Player Thread Being fed up with Windows Media Player lagging and screwing up my playlist I decided to pursue my own audio player. I used the Windows WaveOut API and made a thread that would control the position while the main thread set it's play/stop/restart flags, and it loads the entire file into memory removing the need for a file ... |
#include #include int main() { char u; char field; int age; printf("Enter you university: \n"); printf("Enter your field: \n"); printf("Enter your age: \n"); scanf("%c", &u); scanf("%c", &field); scanf("%d", &age); if ( u == 'i') { if ( age >= 25) printf("Congratulation 1"); else if (age >=25 && age <=30) printf("Congratulation 2"); else printf("Sorry 1"); } else { if(age >= ... |
HI, I would greatly appreciate some help regarding a problem i am facing. I am using pcap libraries in C to capture packets from one interface and then send them to another interface. I am using threads to do both the tasks. The problem that i am facing is that the receiving thread which runs the pcap_loop function , which takes ... |
[Note: this is not a C question]. Generally, synchronisation between threads and processes would be done using particular types of objects known as critical sections, mutexes, semaphores, or events. The techniques to create these objects, and to use them, vary with operating system (as do the type of synchronisation objects supported by different systems). Note that different methods have different trade-offs, ... |
Code: int sig_caught; /* signal caught */ int rc; /* returned code */ rc = sigwait (&signal_mask, &sig_caught); if (rc != 0) { /* handle error */ } switch (sig_caught) { case SIGINT: /* process SIGINT */ ... break; case SIGTERM: /* process SIGTERM */ ... break; default: /* should normally not happen */ fprintf (stderr, "\nUnexpected signal %d\n", sig_caught); break; ... |
#include #include #include #include #include #include void do_404(char *item, FILE *fp); void process( char *rq, FILE *fp); int main(int ac, char *av[]) { char *buf; int counter=0; FILE *fp, *fpin, *fpout; struct sockaddr_in addr; addr.sin_family= AF_INET; addr.sin_port=htons(7000); char *request; char hostname[256]; int adlen,fd,bd,new,ln; pthread_t thread1, thread2; fd=socket(AF_INET, SOCK_STREAM, 0); bd=bind(fd, (struct sockaddr *)&addr, sizeof(addr)); //if(fd== -1) //perror("Creation error"); //if(bd== -1) //perror("socket ... |
#include #include #include #include using namespace std; const int num_threads = 4; char str[100]; void *thread_function(void *ptr) { pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;; pthread_mutex_lock(&mtx); char temp[25]; sprintf(temp, " I am here %d :", pthread_self()); sleep(1); strcat(str, temp); pthread_mutex_unlock(&mtx); } int main() { strcpy(str, ""); pthread_t threads[num_threads]; for(int i = 0; i < num_threads; i++) { pthread_create (&threads[i], NULL, ... |
|
I have bunch of functions for my pmm, but I came up with the problem: "What if another thread or process(assuming I ever get to that point) calls and allocates a page already assumed free in another that is paused(there inherently has to be some time between checking if a page is free and marking it used)?" If tried to make ... |
hello, it is a book database i have made 3 functions out of 5 plz help me these functions are not giving right output .plz plz plz help. i wil be highly thankful to him/her.plz Code: #include #include #include struct data { int book_id; char authername[89]; char bookname[80]; float price; }; struct data book[40]; void menu(void); void add(void); void sort(void); void ... |
Why does this program prints many times the red point? thanks in advance... Code: #include #include #include struct myInfo{ char my_name[81]; char my_phone[81]; char my_street[81]; char my_email[81]; }; struct Info{ char name[81]; char phone[81]; char street[81]; char email[81]; }; // It prints name, phone, address, and e-mail. void print(struct Info info){ printf("Diagnostic.\n\n"); } int main(void){ int choice; char ... |
84. threads & cgi cboard.cprogramming.com |
|
|
Is it possible to take existing code, which is not set up for multi-threading and write my own code that basically applies the concept. Say I have a program that is going to generate a predermined amount of objects and manipulate them in sequential order (one after the other), dragging out runtime. Code: for(i=0;i=NUM_OBJECT;i++) { //generate object //manipulate it //let's say ... |
|
Code: void *getSize (void *dirname) { pthread_t newThread; char * dir; dir = (char *) dirname; DIR* handle = opendir(dir); struct dirent* entry; struct stat statbuf; int * val = malloc(sizeof (int)*1); val[0] = 0; puts(dir); while((entry = readdir(handle)) != NULL) { printf("The file name is %s\n", entry->d_name); while((entry = readdir(handle)) != NULL) { if( (strcmp((entry->d_name), ".") > 0) && (strcmp((entry->d_name), ... |
Hey all. I have been working on this problem for well over 3 hours and I think its time to ask for help. What the program should do is create a thread within a thread. Now the only way I know how to do this is with a struct. Now whenever I run my code I keep getting seg. faults. Here ... |
Code: int main(int argc, char *argv[]) { int sock; int conn; pid_t pid; struct sockaddr_in servaddr; /* Create socket */ sock = socket(AF_INET, SOCK_STREAM, 0); /* Populate socket address structure */ memset(&servaddr, 0, sizeof(servaddr)); servaddr.sin_family = AF_INET; servaddr.sin_addr.s_addr = htonl(INADDR_ANY); servaddr.sin_port = htons(SERVER_PORT); /* Assign socket address to socket */ bind(sock, (struct sockaddr *) &servaddr, sizeof(servaddr)); /* Make socket a listening ... |
snode=scurr=pktlist; while(scurr->next!=NULL) // FIRST CHECKS FOR THE SMALLEST PACKET. { if(snode->ts.tv_sec < scurr->ts.tv_sec && snode->ts.tv_usec < scurr->ts.tv_usec) { TMPNode=snode; snode=scurr; scurr=TMPNode; } scurr=scurr->next; } gettimeofday(&curr_time,NULL); //SENDS THE PACKET IF THE PACKET TIMESTAMP IS SMALLER THAN THE CURRENT TIME. if(curr_time.tv_sec >= snode->ts.tv_sec && curr_time.tv_usec >= snode->ts.tv_usec) { struct sockaddr_ll destAddr; memcpy(buf,&snode->pkt,snode->pkt_len); memcpy(&(destAddr.sll_addr),&buf,MAC_ADDR_LEN); destAddr.sll_family=PF_PACKET; destAddr.sll_protocol=htons(ETH_P_ALL); destAddr.sll_ifindex=2; destAddr.sll_pkttype=PACKET_OTHERHOST; destAddr.sll_halen=ETH_ALEN; if(snode2->rFlag==0 && snode2->wFlag==1) { if((retVal=write(Fd,snode->pkt,snode->pkt_len))==-1) ... |
|
94. threads cboard.cprogramming.com |
95. Threads cboard.cprogramming.com |
Hi, Currently I am playing with multithreading a bit. I use POSIX threads (header file: pthread.h). I quickly read some tutorials and I wanted to apply what I had learned to a prime calculation program. The user inputs number of threads and maximum number to calculate. This works perfectly, no compiler errors or warnings and no segmentation faults. The prime numbers ... |
|
98. Threads cboard.cprogramming.comHey guys...I am having trouble with this program here as I am rusty in C and just learning about threads. The .c file has all of the instructions commented out and where the lines of code are below the commented out numbers is where I filled in the work. I am specifically haveing a problem with the pthread_cancel(); I really do ... |
Multiple Threads I am trying to create multiple threads in a client/server program but I am only able to run one thread at a time. Here is a copy of what I have thus far and I always open to suggestions and/or directions of what to look into Code: #include #include #include #include #include #include ... |
|