我可以让pthread_t实例超出范围吗?(Can I let pthread_t instance go out of scope?)
我用C和pthreads编程。 我有一个长期运行的函数,我想在一个单独的线程中运行:
void long_running_function(void * arg) { ... } void start_long_running_function(void * arg) { pthread_t thread; pthread_create( &thread , NULL , long_running_function , arg); /* What about the thread variable? */ }
离开start_long_running_function()函数时,局部变量'thread'将超出范围。 这样可以 - 或者我可以冒险解决问题,例如当long_running_function()完成时?
我已经尝试过在我的代码中说明的方法,它似乎有效 - 但也许这只是运气?
关心Joakim
I am programming with C and pthreads. I have a long running function which I want to run in a seperate thread:
void long_running_function(void * arg) { ... } void start_long_running_function(void * arg) { pthread_t thread; pthread_create( &thread , NULL , long_running_function , arg); /* What about the thread variable? */ }
When leaving the start_long_running_function() function the local variable 'thread' will go out of scope. Is this OK - or can I risk problems e.g. when the long_running_function() is complete?
I have tried the approach illustrated in my code, and it seems to work - but maybe that is only luck?
Regards Joakim
原文:https://stackoverflow.com/questions/6855857
最满意答案
I would try using a while loop to encase the switch. So it keeps asking your input. import java.util.Scanner; public class SwitchTry { public static void main(String[] args) { while(true){ int mth; String mthString; Scanner scanner = new Scanner(System.in); mth =scanner.nextInt(); switch (mth) { case 1: mthString = "January"; break; case 2: mthString = "February"; break; case 3: mthString = "March"; break; case 4: mthString = "April"; break; case 5: mthString = "May"; break; case 6: mthString = "June"; break; case 7: mthString = "July"; break; case 8: mthString = "August"; break; case 9: mthString = "September"; break; case 10: mthString = "October"; break; case 11: mthString = "November"; break; case 12: mthString = "December"; break; default: mthString = "Error"; break; } System.out.println(mthString); } } }
I would try using a while loop to encase the switch. So it keeps asking your input. import java.util.Scanner; public class SwitchTry { public static void main(String[] args) { while(true){ int mth; String mthString; Scanner scanner = new Scanner(System.in); mth =scanner.nextInt(); switch (mth) { case 1: mthString = "January"; break; case 2: mthString = "February"; break; case 3: mthString = "March"; break; case 4: mthString = "April"; break; case 5: mthString = "May"; break; case 6: mthString = "June"; break; case 7: mthString = "July"; break; case 8: mthString = "August"; break; case 9: mthString = "September"; break; case 10: mthString = "October"; break; case 11: mthString = "November"; break; case 12: mthString = "December"; break; default: mthString = "Error"; break; } System.out.println(mthString); } } }
相关问答
更多-
按状态过滤ng-repeat(Filter ng-repeat by status)[2023-12-04]
您需要执行以下操作: selectedStatus将是下拉菜单中ng-model的值。 Under the circumstances, it ended up just being easier to write my own function and filter by it. In this case, I have a ... -
您可以使用ngShow 。
- No events
参见示例 。 或者你可以使用ngHide- No events
参见示例 。 对于对象,您可以测试Object.keys 。 You can use ngShow.- No events
See example. Or you can use ngHide < ... -
重复输入事件(Repeat input events)[2019-11-29]
您可以在inputText上添加.setOnClickListener(),并且当单击inputText时,您将在该部分中执行代码。 在代码运行后,您可以调用另一个事件,并根据需要多次执行此操作。 把这些放在OnCreate方法中: EditText inputText = (EditText) findViewById(R.id.edittextname); inputText.setOnClickListener(action1); OnCreate后,放: public void action2 ( ... -
试试这个,因为即使对单个和多个对象也是如此
- {{relation.name}}
-
提示用户重复输入(Prompt user to repeat the input)[2022-03-10]
把你的while循环放在下面的循环中 public static void main(String[] args) { while (true) { Scanner read = new Scanner(System.in); System.out.println("Enter the phone number: "); String telLetter = read.next().toUpperCase(); Str ... -
我觉得你不需要任何左连接。 我认为只需要围绕table1而不是table0构建查询。 select t.fatherCode, f.itemName, t.childCode, c.itemName as itemName2, t.childNum from Table1 t join Table0 f on f.itemCode = t.fatherCode join Table0 c on c.itemCode = t.childCode I don't think you ...
-
显然没有办法绕过它,gamedev教程解释说你只需要在自己的代码中使用自己复杂的解决方法来处理它。 Raw输入我的微软。 当你按住一个键时会发生什么WM_INPUT会发送一个按键消息,等到Windows“按键重复延迟”过去,然后继续以Windows“按键重复速度”设置发送按键信息。 我发现不是使用Makecode或Vkey成员,而是使用keyboard.flags成员更容易,因为(对于大多数键)当键处于关闭状态时,此标志将为零,当它向上时,该标志将设置为1,所以你可以通过以下方式将其反转: switch ...
-
你可以试试这个。 Select MAX(case when REPORTING_DATE = Convert(datetime, '2016-11-30') then 1 else 0 end) OVER(PARTITION BY ID) as November , Reporting_Date , ID from TableA where 1=1 You can try this. Select MAX(case when REPORTING_DATE = ...
-
输入重复相同的情况(Input Repeat with same case)[2021-08-10]
I would try using a while loop to encase the switch. So it keeps asking your input. import java.util.Scanner; public class SwitchTry { public static void main(String[] args) { while(true){ int mth; String mthString; Scanner scanner = new Sc ... -
loop do choice = gets.chomp.upcase case choice when "S", "T", "C", "A", "O" @klass = "#{choice} Klass" @extra = "#{choice} Extra" puts "#{choice} Story" break end end loop do choice = gets.chomp.upcase case choice ...