473,404 Members | 2,213 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

problems with threads and gdb

1.
#include <stdio.h>
2.
#include <stdlib.h>
3.
#include <string.h>
4.
#include <pthread.h>
5.
#include <sys/types.h>
6.
#include <sys/stat.h>
7.
#include <fcntl.h>
8.
#include <errno.h>
9.

10.

11.
pthread_mutex_t file_lock = PTHREAD_MUTEX_INITIALIZER;
12.

13.

14.

15.
void th_funz(void* arg)
16.
{
17.
int rc;
18.
int fd;
19.
FILE* f;
20.
char* point;
21.
int nread = 1;
22.

23.
int *id = (int*) arg;
24.

25.

26.
rc = pthread_mutex_lock(&file_lock);
27.
if (rc) perror("pthread_mutex_lock");
28.

29.
printf("th %d comes..\n", *id);
30.
sleep(4);
31.

32.
rc = pthread_mutex_unlock(&file_lock);
33.
if (rc) perror("pthread_mutex_unlock");
34.

35.
}
36.

37.

38.
int main()
39.
{
40.

41.
pthread_t th1, th2, th3;
42.
int rc;
43.
int uno= 1, due = 2, tre= 3;
44.

45.
rc = pthread_create(&th1, NULL, th_funz, (void*) &uno);
46.
if (rc < 0) perror("pthread_create()");
47.

48.
rc = pthread_create(&th2, NULL, th_funz, (void*) &due);
49.
if (rc < 0) perror("pthread_create()");
50.

51.
rc = pthread_create(&th3, NULL, th_funz, (void*) &tre);
52.
if (rc < 0) perror("pthread_create()");
53.

54.
pthread_join(th1, NULL);
55.
pthread_join(th2, NULL);
56.
pthread_join(th3, NULL);
57.

58.
return 0;
59.

60.
}
61.

62.
when i debug this sample program with gdb and set a breakpoint into pthread_mutex_lock() line
63.
i got sigtrap:(gdb) b prova.c:26
64.
Breakpoint 1 at 0x8048547: file prova.c, line 26.
65.
(gdb) r
66.
Starting program: /progetto/fd_threads/prova
67.
[Thread debugging using libthread_db enabled]
68.
[New Thread -1208653568 (LWP 20212)]
69.
[New Thread -1209922640 (LWP 20215)]
70.
[Switching to Thread -1209922640 (LWP 20215)]
71.

72.
Breakpoint 1, th_funz (arg=0xbfb86994) at prova.c:26
73.
26 rc = pthread_mutex_lock(&file_lock);
74.
(gdb) n
75.
[New Thread -1218311248 (LWP 20216)]
76.

77.
Program received signal SIGTRAP, Trace/breakpoint trap.
78.
[Switching to Thread -1208653568 (LWP 20212)]
my gdb version is 6.3-debian
thx everybody!
Sep 3 '06 #1
1 2218
fabio <fa*@localhost.localdomainwrites:
1.
#include <stdio.h>
2.
#include <stdlib.h>
3.
#include <string.h>
4.
#include <pthread.h>
[snip]
62.
when i debug this sample program with gdb and set a breakpoint into pthread_mutex_lock() line
63.
i got sigtrap:(gdb) b prova.c:26
64.
Breakpoint 1 at 0x8048547: file prova.c, line 26.
[...]

Standard C doesn't support threads. Try comp.programming.threads or
comp.unix.programmer.

BTW, the line numbers aren't helpful.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Sep 3 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Rob Durant | last post by:
Hi, I have a multi-threaded application (have also tried as service - same behaviour) that runs fine on XP, but not on 2003. Symptoms are: Threads are started normally, locks acquired and...
4
by: - R | last post by:
Hello all. I'm new to .Net so please help me out. I have a application with several "Threads" running to observe various things. From time to time each thread need to add an log entry, which...
7
by: Mr. Mountain | last post by:
In the following code I simulate work being done on different threads by sleeping a couple methods for about 40 ms. However, some of these methods that should finish in about 40 -80 ms take as long...
11
by: Rick Mogstad | last post by:
I know this is probably not the group for this, but i know that these groups are fairly active, and that the people are usually willing to help. Is anyone else experiencing this? The news...
1
by: rwaddell | last post by:
I'm using Visual Studio 2005 Pro final, and I've noticed some bizarre behaviour when I'm debugging programs with multiple threads. Specifically, if I set a breakpoint in one of my non-UI threads,...
11
by: Steve Smith | last post by:
I have written a winforms application that launches approximately 150 threads with Thread.ThreadStart() Each thread uses CDO 1.21 to logon to a different Exchange mailbox and send/receive a...
8
by: pavvka | last post by:
I'm making multithread server on Linux. Everything works fine, but server reaches threads limint and cannot create any one more. I've wrote simple test code to test this problem. #include...
1
by: Sam | last post by:
Hi All, I'm trying to write a simple multi-threaded windows service application using ThreadPool and I'm running into the same problem as described by MS article:...
8
by: John Olbert | last post by:
Subject: Problems with Interop in C# We are having problems using Interop with a Vb6 ActiveX Dll in C# code in Net2 using Vs2005. Below are the signatures of the method that is the problem. It...
4
by: Marcus Alves Grando | last post by:
Hello list, I have a strange problem with os.walk and threads in python script. I have one script that create some threads and consume Queue. For every value in Queue this script run os.walk()...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.